Banner Advert
Yaroslav Pentsarskyy
Posted on February 7, 2013 by
1 Comment

Once a while, SharePoint developers around the world have a pleasure of building list views SPView, programmatically.


list view


I’m not going to waste your time on explaining why you’d build an SPView programatically, chances are, if you’re reading this, you just need to build one, and here is a cool new approach I want to share with you.


1. Navigate to your list, click List Settings
2. Scroll to the view of your interest or create a new one
3. Modify the view using a UI to match your desired configurations, such as query, filter etc


view filter


4. Ensure you’re in the Edit mode of the view
5. The query string in your browser will look similar to this:


http://sp2010/_layouts/ViewEdit.aspx?List=%7B8081FF0B%2DCA48%2D4EC0%2DB540%2DA30CBA8C33B4%7D&View=%7B90BFF3B5%2D4F58%2D48CA%2D8CE6%2DE7A48306279A%7D&


6. Replace the “/_layouts/ViewEdit.aspx?” with the “/_vti_bin/owssvr.dll?Cmd=ExportList&”
In essence your URL will become:


http://sp2010/_vti_bin/owssvr.dll?Cmd=ExportList&List=%7B8081FF0B%2DCA48%2D4EC0%2DB540%2DA30CBA8C33B4%7D&View=%7B90BFF3B5%2D4F58%2D48CA%2D8CE6%2DE7A48306279A%7D&


7. Hit the URL and you will be offered to download the file owssrv.xml; what’s this? this is the view XML in here you can extract the query, the filter parameters and other fields required to build your custom view:


For example:

<ViewData><FieldRef Name="Title" Type="CalendarMonthTitle"/><FieldRef Name="Title" Type="CalendarWeekTitle"/>< ...


PS: More tips and trick like this, specifically on SharePoint 2013 in my new book here

Enjoy!

 

This article was originally posted here.

One Comment

Chris on February 7, 2013

Very good tip!

Add a comment