SPQuery.ViewXml property
取得或設定定義檢視表的 XML 結構描述。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Property ViewXml As String
Get
Set
'用途
Dim instance As SPQuery
Dim value As String
value = instance.ViewXml
instance.ViewXml = value
public string ViewXml { get; set; }
Property value
Type: System.String
字串,包含檢視中的結構描述共同作業應用程式標記語言。
備註
ViewXml屬性包含對應至檢視中的項目連同 CAML 內部 XML 字串。
注意事項 |
---|
如需有關如何使用 Language-Integrated 查詢 (LINQ) 查詢來擷取清單項目,在SharePoint Foundation中的資訊,請參閱Managing Data with LINQ to SharePoint。 |
Examples
下列程式碼範例會使用ViewXml屬性,來定義連同 CAML 中的查詢。
這個範例要求using指示詞 (Imports Microsoft Visual Basic 中), Microsoft.SharePoint和Microsoft.SharePoint.Utilities命名空間。
Dim webSite As SPWeb = SPContext.Current.Site.AllWebs("Site_Name")
Try
Dim list As SPList = webSite.Lists("List_Name")
Dim query As New SPQuery()
query.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>"
Dim items As SPListItemCollection = list.GetItems(query)
Dim item As SPListItem
For Each item In items
Response.Write((SPEncode.HtmlEncode(item.Xml) + "<BR>"))
Next item
Finally
webSite.Dispose()
End Try
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>");
}
}
注意事項 |
---|
某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects。 |