Simple way to remove webpart in a page programmatically. [Here I am trying to remove all webparts which are added to 'dafault.aspx' page when I created to Report site]
[SPLimitedWebPartManager is under "microsoft.sharepoint.webpartpages" namespace]
SPLimitedWebPartManager reportWebPartManager = sourceWeb.GetLimitedWebPartManager("Pages/default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
int webPartCount = reportWebPartManager.WebParts.Count;
for (int i = webPartCount - 1; i >= 0; i--)
{
reportWebPartManager.DeleteWebPart(reportWebPartManager.WebParts[i]);
}
reportWebPartManager.Dispose();
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment