Online Training On SharePoint

Thursday, 24 July 2008

Creating a view to show all items in a list in SharePoint

If we want to show all the items in a list even when they are stored in multiple folders inside a list we need to use SPViewScope.Recursive. To use this we can create a new view with SharePoint object Model and then use this Recursive property. This view will show all the items in a flat list irrespective of folder hierarchy in the list.

Here is the code snippet:

SPSite spsite = new SPSite("http://mysite/");
SPWeb spweb = spsite.OpenWeb();
SPList splist = spweb.Lists["mylist"];
SPViewCollection spviewcollection = splist.Views;
string strMyView= "MyView";
System.Collections.Specialized.StringCollection viewColumnFields =
new System.Collections.Specialized.StringCollection();
string filter =

//show all the items which has age less than 100
spviewcollection.Add(strMyView, viewColumnFields, filter, 100, true, true);
//This will add the view in the list and make it the default view
spview.Scope = SPViewScope.Recursive;
//With this all the items inside the folders will be displayed

Thursday, 17 July 2008

Locking SharePoint Site for Read/Edit

We can use a stsadm command to lock a Sharepoint site for further read or write when we are doing the maintenance on the site. This feature comes really handy.
The command to use for this purpose is:
stsadm -o setsitelock -url http://localhost -lock {none noadditions readonly noaccess}
Here we have 4 kind of locks available:
None: This option sets the site collection to unlock. With this site will be open to read and write.
Noadditions: This option stops any new addition to the data. Suppose we have 1000 character in a list. With this option user can reduce this 1000 char but can not further add any character.
Readonly: With this no write operation will be allowed. Site will become read only.
Noaccess: This value sets the site collection unavailable to all users. User can not access the SharePoint Site.
Also we can use the following STSADM command to get the lock status for the site:
stsadm -o getsitelock -url http://localhost
Related Posts with Thumbnails