SharePoint Filter List / Library by Querystring
If you need to filter a list / library, but don’t want to have to make new View .ASPX files, it’s a simple but effective thing to know that standard Views accepts querystring filter values. So can you put in filter/order/etc. values directly into the URL to accomplish your goal. You could always batch create Views using PowerShell with a technique like the one described here, however if you want to keep things in one simple view then go with the query string approach.
http://go.mysharepoint.com/SiteName/LibraryName/Forms/ChangeLogMergeView.aspx?FilterField1=MyColumn&FilterValue1=Custom Value
You’ll need the following querystring values:
FilterField1 (first filter, column to filter by)
FilterValue1 (first filters, the string you want to filter by)
If you have multiple clauses to filter by, just add another pair of FilterField1 / FilterValue2 pairs, and increment by one, so:
http://go.mysharepoint.com/SiteName/LibraryName/Forms/ChangeLogMergeView.aspx?FilterField1=MyColumn&FilterValue1=Custom Value&FilterField2=MyOtherColumn&FilterValue2=Another Custom Value
The one to watch out for is the FilterField which is looking for the CAML Query-style name of the field. So if you wanted to filter by a field name that has spaces in it, you need to replace the spaces with _x0020_ (which represents a space character). So “Date Modified” becomes:
&FilterField1=Date_x0020_Modified
filter by url, filter list, filterfield1, filtervalue1, query string
Flint
Hey Keith,
Thanks for sharing the knowledge! I was playing around with this and I was able to get it working, but was wondering if there was a way to filter multiple fields, but with an OR clause:
FilterField1=xxx&FilterValue1=xxx
OR
FilterField2=xxx&FilterValue2=xxx
Keith Tuomi
I don’t believe OR is supported as a Filter querystring value. You could alternately see if using the search syntax available in SP 2010 to get the results you want: See http://www.sharepoint911.com/blogs/john/Lists/Posts/Post.aspx?ID=39 and http://www.sharepoint911.com/blogs/john/Lists/Posts/Post.aspx?List=729952ef%2Dc6ee%2D46d0%2D9c2b%2Db2555e87775b&ID=10&Web=657e941a%2D3dde%2D41d9%2D873a%2D6a91bbc7e9ec
Bruce Wallace
Hi Keith,
Is there a way to use Library QueryString to call up the most recently added document in a list or folder?
I’d like to dynamically call up display that document in a web page.
Thanks for your time,
Bruce
Keith Tuomi
Most definitely –
Just to clarify the terminology first: everything in SharePoint is a “list” however we do refer to Lists that have the primary item being a document, as Document Libraries. I’m going to assume this is what you are referring to. You can have files as attachments in lists, however sorting them via querystring would be a different matter.
1. Add the “Created” column to the view – Here’s a reference for working with views: http://office.microsoft.com/en-ca/sharepoint-server-help/create-modify-or-delete-a-view-HA010377693.aspx
2. Go to the Library and click on the “Created” column header so that it sort’s descending
3. Note the change in the URL. It will look something like https://go.mySharePointSite.com/sites/MySite/Shared%20Documents/Forms/AllItems.aspx#InplviewHashb7effaed-54c3-46d3-a613-0234e6f5232c=SortField%3DCreated-SortDir%3DDesc. You can borrow this URL and provide it elsewhere for users or manipulate it with JavaScript/other code.