How to programmatically update content in a SharePoint Web Part? -


Do anyone know whether to update the contents of any standard SharePoint v3 Web Parts programmatically?

As an example, enter a link summary web part on a page. Add some links to it Now, how can I update this information using the WSS API? I have not found any direct way to do this, my only idea is to export the web part (then delete it), modify XML, and import it back but surely, should be an easy way?

You can use the class to manipulate web parts The example can be obtained from the SPA file object:

 using  (SPS ite site = new SPS ite ("& lt; site url & gt;")) eg Http: // server / sites / asite (SPWeb web = site.OpenWeb ()) {SPFile file = web.GetFile ("& lt; page url & gt;"); Eg eg /sites/asite/default.aspxSPLimitedWebPartManager lwpm = file.GetLimitedWebPartManager (); SPLimitedWebPartCollection webParts = lwpm.WebParts; WebPart wp = webParts [& lt; ID, index or guide & gt;]; // Add your code to update web part lwpm.SaveChanges (wp); }  

You can also add or remove Web Parts with SPLimitedWebPartManager.


Comments