Some code I found from awhile back that may help others if they need to get the web part from a page that is not the current page.

This will need to be adjusted however right now it shows how to open the Page in a way to get the web part manager, then test to see if a type of web part is part of the page, then updates the manager. If you need to update the web parts themselves you might just need to swap the foreach to a for loop to avoid adjusting the enumeration during the loop as well as calling an update on the webpart if there is one.

SPContext.Current.Web.AllowUnsafeUpdates = true;
SPFile file = SPContext.Current.Web.GetFile("http://win-j1151qbc1qm:48055/sites/asaasdasda/Pages/Page1.aspx");
SPLimitedWebPartManager webpartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);

SPLimitedWebPartCollection webpartCollection = webpartManager.WebParts;
foreach (Object listWebPart in webpartCollection)
	if(listWebPart.GetType() == typeof(XsltListViewWebPart))
		XsltListViewWebPart part = (XsltListViewWebPart)listWebPart;

		if (part.Title == "")


No Comments

There are no comments related to this article.