The other day, I found myself in need of a way to access SharePoint list data as XML but the only method available to me was a simple http GET. This is not too bad, but what can I get from SharePoint via GET? RSS is too limited and scraping the page is too painful and error-prone to even contemplate.
It turns out that there is an option available in 2007 that was carried forward from SharePoint 2003 / FrontPage days: owssvr.dll. But this isn't some forgotten FrontPage artifact, it is still a central part of SharePoint. In fact, if you pull up a list view and then view the source looking for owssvr.dll, you will see that this is the mechanism behind both the Export to Spreadsheet and Open with Access options on the list Actions menu.
How It Works
Simply put together a URL like this:
This will only return the fields that are defined on the default view of the list. If you need specific fields then you need to create a view with those fields and pass the View ID as well, like this:
Specifying Fields to be Returned
There is also a Query parameter that lets you specify which fields are to be included in the resulting XML, regardless of how the view is defined. For example, if you wanted just to bring back the Title and Status Fields, you would add the field names separated by spaces (URL Encoded, of course) like "&Query=Title%20Status". If you want to return all fields, use an asterisk (*) instead of field names.
Regardless of whether you pass a view or use the default it will still use the filter defined by that view. Not bad, but you can trim this data even more by including a filter of your own using the FilterFieldn and FilterValuen arguments in the querystring. These are the same values that are passed when you use the filter options in the column headers of a view which makes it pretty easy to track down exactly what needs to be passed. Simply pull up the view that is your starting point and use the column filters to create your desired filter. Once you have it, grab all of the FilterField and FilterValue items from the querystring and add them on to yours.
For a full list of what can be done with this technique, check out the URL Protocol or the older Using the URL Protocol on MSDN.
5 thoughts on “Accessing SharePoint List Data as XML”
Have you ever got the the &View=GUID working. Try as I might, I can’t get anything back except an empty document.
It looks like when I pass the View ID in the url, it is not taken into account and the default view is always displayed.
did i miss something?
Is there any way to bring back specific field names that have spaces in them?
It doesnt seem like it…
Who uses spaces as a delimiter????
I dont know why microsoft would allow using spaces in column names if they arent going to actually support it 100%….
Keep in mind that this post was from way back in the SharePoint 2007 world. Microsoft has since added the REST API to SharePoint that provides a different way to accomplish roughly the same thing. You might want to look into those for this task instead. http://msdn.microsoft.com/en-us/magazine/dn198245.aspx