Creating Views in SharePoint Using the object model
Using the object model we can create a SharePoint views programmatically. The query for
the view uses an SPQuery which uses CAML.
//Define an array to hold the columns required in the view
String[] colArray = new String[] { "FName", "LName", "Email” };
//Add the array to a string collection
StringCollection colCollection = new StringCollection();
colCollection.AddRange(colArray);
//Define the query for the view
String viewQry = “Your CAML Query Here’;
HTML clipboard //Define the new view & Add to the List (100 is the item limit, true is allow paging and false is to set as the default view)
SPView newView = YourList.Views.Add(“View Title”, colCollection, viewQry, 100,true, false);
the view uses an SPQuery which uses CAML.
//Define an array to hold the columns required in the view
String[] colArray = new String[] { "FName", "LName", "Email” };
//Add the array to a string collection
StringCollection colCollection = new StringCollection();
colCollection.AddRange(colArray);
//Define the query for the view
String viewQry = “Your CAML Query Here’;
SPView newView = YourList.Views.Add(“View Title”, colCollection, viewQry, 100,true, false);
Comments
Post a Comment