开发者

How to create a list item for seeing all created views

开发者 https://www.devze.com 2023-03-31 10:33 出处:网络
How to create a view which displays all开发者_开发问答 the views that are present in Share point server 2007

How to create a view which displays all开发者_开发问答 the views that are present in Share point server 2007

Thanks in advance


I apologize for how rough this is but it should hopefully point you in the right direction. I'm not sure if you want to do this for an entire site collection or for individual webs so I did it for a single web but this snippet can be expanded on.

  1. Create your SPSite and SPWeb objects.
  2. I am assuming this list will reside at the same level as the lists it is referencing. Create a List called ViewsList at the same site level. Give it columns List Name and View Name.

Once you have that setup:

SPListCollection lists = web.Lists; //Get all lists in the site   
SPList viewsList = web.Lists["ViewsList"]; //Get reference to the list ViewsList

foreach(SPList list in lists)  //Iterate over all of the lists in the site
{
    SPViewCollection views = list.Views;  //Get all of the views associated with the current list

    foreach(SPView view in views)
    {            
       SPListItem newItem = viewsList.Items.Add();  //create item object to add to list.
       newItem["List Name"] = list.Title; //populate columns
       newItem["View Name"] = view.Title;
       newItem.Update(); //add item to list
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号