如何以編程方式刪除SharePoint列表視圖?如何在C#,Sharepoint 2010中以編程方式刪除列表視圖?
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個視圖是自定義的,並且名稱相同。即。 MyCustomView
上面的代碼是正確答案了。我修改了正確的錯誤代碼(工作代碼) – Gaurravs