Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have copied a lot of products and product categories from one language to another and would like to change the language property on all children.
public string UpdateLanguage(int id = 0) { if (id == 0) { id = 5294; // All children below this node need to have Language property updated! } Document doc = new Document(id); if (doc.HasChildren) { Document[] children = doc.Children; var res = ""; foreach (Document child in children) { res += "<br>" + child.Id; if (child.HasChildren) { if (child.Id > 0) { UpdateLanguage(child.Id); } } //child.getProperty("Language").Value = "PL"; } return res; //umbraco.library.RefreshContent(); } return "0"; }
When i Invoke this method i get "
Cannot convert to System.Int32.
Turned out my problem was with getProperty where i used Name and not Alias
This is what i ended up with
[WebMethod(MessageName = "updatelanguages", Description = "UpdateProductLanguages")] public string UpdateLanguage() { Document doc = new Document(5294); //5294 //5300 if (doc.HasChildren) { Document[] children = doc.Children; foreach (Document child in children) { try { child.getProperty("productLanguage").Value = "PL"; child.getProperty("categoryLanguage").Value = "PL"; } catch (Exception e) { } if (child.HasChildren) { UpdateLanguage(child.Id); } } umbraco.library.RefreshContent(); } return "0"; } public string UpdateLanguage(int id) { Document doc = new Document(id); if (doc.HasChildren) { Document[] children = doc.Children; foreach (Document child in children) { try { child.getProperty("productLanguage").Value = "PL"; child.getProperty("categoryLanguage").Value = "PL"; } catch (Exception e) { } if (child.HasChildren) { UpdateLanguage(child.Id); } } } return "0"; }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
get all children in webservice
I have copied a lot of products and product categories from one language to another and would like to change the language property on all children.
public string UpdateLanguage(int id = 0)
{
if (id == 0)
{
id = 5294; // All children below this node need to have Language property updated!
}
Document doc = new Document(id);
if (doc.HasChildren)
{
Document[] children = doc.Children;
var res = "";
foreach (Document child in children)
{
res += "<br>" + child.Id;
if (child.HasChildren)
{
if (child.Id > 0)
{
UpdateLanguage(child.Id);
}
}
//child.getProperty("Language").Value = "PL";
}
return res;
//umbraco.library.RefreshContent();
}
return "0";
}
When i Invoke this method i get "
Turned out my problem was with getProperty where i used Name and not Alias
This is what i ended up with
[WebMethod(MessageName = "updatelanguages", Description = "UpdateProductLanguages")]
public string UpdateLanguage()
{
Document doc = new Document(5294); //5294 //5300
if (doc.HasChildren)
{
Document[] children = doc.Children;
foreach (Document child in children)
{
try
{
child.getProperty("productLanguage").Value = "PL";
child.getProperty("categoryLanguage").Value = "PL";
}
catch (Exception e)
{
}
if (child.HasChildren)
{
UpdateLanguage(child.Id);
}
}
umbraco.library.RefreshContent();
}
return "0";
}
public string UpdateLanguage(int id)
{
Document doc = new Document(id);
if (doc.HasChildren)
{
Document[] children = doc.Children;
foreach (Document child in children)
{
try
{
child.getProperty("productLanguage").Value = "PL";
child.getProperty("categoryLanguage").Value = "PL";
}
catch (Exception e)
{
}
if (child.HasChildren)
{
UpdateLanguage(child.Id);
}
}
}
return "0";
}
is working on a reply...