How to create a list item for seeing all created views
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.
- Create your SPSite and SPWeb objects.
- 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
}
}
精彩评论