Creating SharePoint/WSS View Programmatically

Creating SharePoint/WSS View Programmatically

Using the object model it is really easy to create a SharePoint view programmatically in code and then add it to a list. This code could be executed from a workflow for example to create a dynamic view as required. The query for the view uses an SPQuery which uses CAML. Personally I like to use the U2U CAML Creator application to create the CAML query for me which was created by Patrick Tisseghem (


[code lang="csharp"]
//Define an array to hold the columns required in the view

String[] colArray = new String[] { "Column1", "Column2", "Column3” };

//Add the array to a string collection

StringCollection colCollection = new StringCollection();


//Define the query for the view

String viewQry = “Your CAML Query Here’;

//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);

**End Code**

Success, your view should now be visible in the list!

Hope this helps someone! :-)

One thought on “Creating SharePoint/WSS View Programmatically

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">