Once a while, SharePoint developers around the world have a pleasure of building list views SPView, programmatically.
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
4. Ensure you’re in the Edit mode of the view
5. The query string in your browser will look similar to this:
6. Replace the “/_layouts/ViewEdit.aspx?” with the “/_vti_bin/owssvr.dll?Cmd=ExportList&”
In essence your URL will become:
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:
<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
This article was originally posted here.