Sort a SPView using code

 Long time no blog….

My current project with MOSS requires doing almost everything programmatically, provisioning sites, constructing site navigation, creating lists, applying content types, etc. I spent a little while to figure how to sort a SPView for a document library. Once you know it, it's actually super easy. Just modify the Query property.

 
Example:

…..
SPView view = list.DefaultView;
view.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>"'
…..

This set the view ordered by the modified date,  the newest document at the top. The default order is by document name. Also we can filter the records for this view since it is CAML query string.

Leave a Reply


Sort a SPView using code

 Long time no blog….

My current project with MOSS requires doing almost everything programmatically, provisioning sites, constructing site navigation, creating lists, applying content types, etc. I spent a little while to figure how to sort a SPView for a document library. Once you know it, it's actually super easy. Just modify the Query property.

 
Example:

…..
SPView view = list.DefaultView;
view.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>"'
…..

This set the view ordered by the modified date,  the newest document at the top. The default order is by document name. Also we can filter the records for this view since it is CAML query string.

Leave a Reply