Updating widget path
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.
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
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.
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
Hi Jen,
That's great, thanks.
I'll try it out soon, and report back.
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();