Updating widget path

Posted by Community Admin on 04-Aug-2018 16:52

Updating widget path

All Replies

Posted by Community Admin on 15-Nov-2011 00:00
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.
Posted by Community Admin on 18-Nov-2011 00:00
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
Posted by Community Admin on 18-Nov-2011 00:00
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.
Posted by Community Admin on 23-Nov-2011 00:00
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
Posted by Community Admin on 23-Nov-2011 00:00
Hi Jen,

That's great, thanks.
I'll try it out soon, and report back.
Posted by Community Admin on 30-Nov-2011 00:00
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();
        
    
This thread is closed