如何以编程方式删除 SharePoint 列表视图?
MyCustomView:是我以编程方式创建的自定义视图。我想删除以相同名称创建的所有视图
using (SPSite oSPsite = new SPSite("http://xxxxxxxxxx:20000/sites/myWA/test"))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
SPList oTransDataList = oSPWeb.Lists["MyDataList"];
oSPWeb.AllowUnsafeUpdates = true;
SPViewCollection oViewCollection = oTransDataList.Views;
int i = 1;
foreach (SPView oViewColl in oViewCollection)
{
if (oViewColl.Title == "MyCustomView")
{
oViewCollection.Delete(oViewColl.ID);
//oTransDataList.Views.Delete(oViewColl.ID);
oTransDataList.Update();
}
}
}
}
我注意到SPViewCollection oViewCollection = oTransDataList.Views;
仅包含 1 个视图。我可以知道为什么会发生这种情况,我有 10 多个视图,其中 9 个视图是自定义的同名视图。IE。我的自定义视图