Friday, August 1, 2008

Programmatically modifying webpart properties

SPSecurity.RunWithElevatedPrivileges(delegate()
{
// get the site in this context
using (SPSite SiteCollection = new SPSite("http://localhost"))
{
// get the web in this context
SPWeb myWeb = SiteCollection.OpenWeb("/");
myWeb.AllowUnsafeUpdates = true;

SPLimitedWebPartManager mgr = null;
mgr = myWeb.GetLimitedWebPartManager("default.aspx",PersonalizationScope.Shared);

foreach (WebPart myWebPart in mgr.WebParts)
{
//If this is the webpart we want to modify...
myWebPart.Title = "New Name" ;
mgr.SaveChanges(myWebPart);
}
}
});


Note:
http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!2005.entry?wa=wsignin1.0&sa=201418415

0 comments: