Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael Falch Madsen 70 posts 92 karma points
    Dec 01, 2010 @ 20:16
    Michael Falch Madsen
    0

    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 "

    Cannot convert  to System.Int32.
  • Michael Falch Madsen 70 posts 92 karma points
    Dec 01, 2010 @ 21:09
    Michael Falch Madsen
    0

    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";
        }

Please Sign in or register to post replies

Write your reply to:

Draft