1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Updating widget path

Updating widget path

6 posts, 0 answered
  1. Thomas
    Thomas avatar
    223 posts
    Registered:
    19 Jan 2011
    15 Nov 2011
    Link to this post
    Hi,

    I have some custom widgets on my site. I sometimes need to move or rename some of them. This time, I need to rename controls because of this issue.

    However, even if I update the toolbox widget paths, pages that reference the widgets will not be automatically updated, and will keep referencing the previous path.

    What is the recommended way to automatically update all existing pages to make them use the new widget path?
    Maybe some kind of script or code snippet?

    Thanks.
  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    18 Nov 2011
    Link to this post
    Hello Thomas,

    We will need some additional time to work on a solution for your scenario. We will get back to you as soon as possible.

    All the best,
    Jen Peleva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Thomas
    Thomas avatar
    223 posts
    Registered:
    19 Jan 2011
    18 Nov 2011
    Link to this post
    Hi Jen,

    Okay. Thanks for the update.
    Meanwhile, I'm thinking of duplicating my widgets (so they'd be available through 2 different paths), so admins can gradually replace them manually without anything breaking.
  4. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    23 Nov 2011
    Link to this post
    Hi Thomas,

    We came up with a solution for your scenario. Please take a look at the attached file. In the code behind of an aspx page we access the page that contains the problematic control (the one that doesn't appear after you change its location). We get the control and change its ObjectType, so that it corresponds the new object type - practically the new path to it. This will automatically update the reference.

    Kind regards,
    Jen Peleva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Thomas
    Thomas avatar
    223 posts
    Registered:
    19 Jan 2011
    23 Nov 2011
    Link to this post
    Hi Jen,

    That's great, thanks.
    I'll try it out soon, and report back.
  6. Thomas
    Thomas avatar
    223 posts
    Registered:
    19 Jan 2011
    30 Nov 2011
    Link to this post
    Hi,

    I tried the code, and it worked nicely. Thanks again.
    I put it in a method, to make it easily reusable:

    /// <param name="oldPath">E.g: "~/Widgets/DocumentList/Main.ascx"</param>
    /// <param name="newPath">E.g: "~/Widgets/DocumentList/DocListWidget.ascx"</param>
    private static void UpdateWidgetPaths(string oldPath, string newPath)
    {
        var manager = PageManager.GetManager();
        var pageNodeList = manager.GetPageNodes().Where(pN => pN.Page != null && pN.Page.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).ToList();
        foreach (var myPage in pageNodeList)
        {
            //Get a list of the controls on the page and check if our control is there
            var controlsList = myPage.Page.Controls.Where(c => c.ObjectType == oldPath).ToList();
            if (controlsList != null && controlsList.Count() != 0)
            {
                //Edit the page
                var master = manager.PagesLifecycle.Edit(myPage.Page);
                //CheckOut to work on a Temp copy
                var temp = manager.PagesLifecycle.CheckOut(master);
                //Get a list of the controls of the desired type on the Temp copy
                var tempControlsList = temp.Controls.Where(c => c.ObjectType == oldPath).ToList();
     
                //Change the ObjectType of each control
                foreach (var myControl in tempControlsList)
                {
                    myControl.ObjectType = newPath;
                }
     
                //Copy the changes and Publish
                master = manager.PagesLifecycle.CheckIn(temp);
                manager.PagesLifecycle.Publish(master);
                manager.SaveChanges();
            }
        }
    }
6 posts, 0 answered