SPView.Query property

Gets or sets a string that contains the query for the view.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public string Query { get; set; }

Property value

Type: System.String
A Collaborative Application Markup Language (CAML) string that contains a Where, Groupby, or Orderby clause for the query.

Setting a query with the Query property requires that the Update method be used for changes to take effect in the database.

The following code example uses the Query property to return items where a specified field in the list contains values less than 1000.

SPSite oSiteCollection = SPContext.Current.Site;
using(SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["View_Name"];

    oView.Query = "<Where><Leq><FieldRef Name=\"Field_Name\" />" +
    "<Value Type=\"Number\">1000</Value></Leq></Where>";


Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.