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)

Syntax

'Declaration
Public Property Query As String
    Get
    Set
'Usage
Dim instance As SPView
Dim value As String

value = instance.Query

instance.Query = value
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.

Remarks

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

Examples

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

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim view As SPView = list.Views("View_Name")

view.Query = "<Where><Leq><FieldRef Name='Field_Name'/>" _
             & "<Value Type='Number'>1000</Value></Leq></Where>"

view.Update()
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>";

    oView.Update();
}

Note

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.

See also

Reference

SPView class

SPView members

Microsoft.SharePoint namespace