Monday, April 2, 2012

Close Shared WebPart Programmatically


These days i have been banging my head between personalized and shared mode of the publishing page.
Well, every publishing page has a shared mode(PageView=Shared) and personalize mode(PageView=Personal). Deleting a webpart from the mode in which it is added is possible but cross deletion is not possible. What i mean is deleting a webpart, added in shared mode from personalized mode .
SharePoint only allows to close such webparts, so how do we that operation programmatic?
Somehow SPLimitedWebPartManager did not work for me in doing this but definitely SPWebPartManager does the trick.

SPWebPartManager spwebPartManager = SPWebPartManager.GetCurrentWebPartManager(this.Page);
SPContext.Current.Web.AllowUnsafeUpdates = true;
if (currentWebPart.IsShared == false)
else if (currentWebPart.IsShared == true)

SPContext.Current.Web.AllowUnsafeUpdates = false;


No comments:

Post a Comment