I am trying to hide or remove a Web Part, a View of a document library, from Webs that have been created using a Site Definition that specifies this View.
In ONET.XML, the following is what sets up the Web Part view.
<Modules>
<Module Name="Default" Url="" Path="">
<File Url="default.aspx" NavBarHome="True" Type="Ghostable">
...
<View List="Documents" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="3" />
...............
When I try and access it via the LimitedWebPartManager, I don't see the Web Part.
Here is the code
using (var web = GetWeb("/path"))
{
Microsoft.SharePoint.WebPartPages.WebPart toDelete = null;
using (var wps = web.GetLimitedWebPartManager(
"default.aspx", PersonalizationScope.Shared))
{
foreach (Microsoft.SharePoint.WebPartPages.WebPart
webpart in wps.WebParts)
{
if(webpart.Title=="Documents")
{
toDelete = webpart;
}
}
if (toDelete != null)
wps.DeleteWebPart(toDelete);
}
}
More information:
The web parts are coming back as Microsoft.SharePoint.WebPartPages.ErrorWebPart
because it is running from a utility rather than a feature or web part.