SPQuery.ViewXml property
Gets or sets the XML schema that defines the view.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
[ClientCallableConstraintAttribute(Type = ClientCallableConstraintType.Custom, FixedId = "aa", Value = "It MUST defines view element")] [ClientCallableAttribute] public string ViewXml { get; set; }
Property value
Type: System.StringA string that contains the view schema in Collaborative Application Markup Language.
The ViewXml property contains a string that corresponds to the inner XML of the View element in CAML.
Note
|
|---|
For information about how to use Language-Integrated Query (LINQ) queries to retrieve list items in SharePoint Foundation, see Managing Data with LINQ to SharePoint. |
The following code example uses the ViewXml property to define a query in CAML.
This example requires using directives (Imports in Microsoft Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.
using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"]) { SPList oList = oWebsite.Lists["List_Name"]; SPQuery oQuery = new SPQuery(); oQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='ID'/>" + "</OrderBy><Where><Or><Geq><FieldRef Name='Field1'/>" + "<Value Type='Number'>1500</Value></Geq><Leq>" + "<FieldRef Name='Field2'/><Value Type='Number'>500</Value>" + "</Leq></Or></Where></Query><ViewFields>" + "<FieldRef Name='Title'/>" + "<FieldRef Name='Field1'/><FieldRef Name='Field2'/>" + "<FieldRef Name='Field3'/><FieldRef Name='Field4'/>" + "</ViewFields><RowLimit>100</RowLimit></View>"; SPListItemCollection collListItemsAvailable = oList.GetItems(oQuery); foreach (SPListItem oListItemAvailable in collListItemsAvailable) { Response.Write(SPEncode.HtmlEncode(oListItemAvailable.Xml) + "<BR>"); } }
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. |
Note