共用方式為


SPQuery.ViewAttributes property

取得或設定在查詢中使用的檢視表的屬性。

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

Syntax

'宣告
Public Property ViewAttributes As String
    Get
    Set
'用途
Dim instance As SPQuery
Dim value As String

value = instance.ViewAttributes

instance.ViewAttributes = value
public string ViewAttributes { get; set; }

Property value

Type: System.String
字串,包含檢視屬性。

備註

ViewAttributes屬性包含用於共同作業應用程式標記語言檢視項目的屬性。例如,如果Scope屬性設定為Recursive (Scope="Recursive"),查詢便會顯示在文件庫,包括子資料夾中的所有檔案。如果設定為任何其他帳戶,查詢會只有檔案顯示在頂端的資料夾。

注意事項注意事項

如需有關如何使用 Language-Integrated 查詢 (LINQ) 查詢來擷取清單項目,在SharePoint Foundation中的資訊,請參閱Managing Data with LINQ to SharePoint

Examples

下列程式碼範例會設定查詢的遞迴範圍,並顯示包含在指定的文件庫中的所有檔案。

這個範例要求using指示詞 (Imports Microsoft Visual Basic 中), Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空間。

Dim webSite As SPWeb = SPContext.Current.Site.AllWebs("Site_Name")
Try
    Dim list As SPList = webSite.Lists("DocLib_Name")
    Dim view As SPView = list.Views("View_Name")

    Dim query As New SPQuery(view)
    query.ViewAttributes = "Scope=""Recursive"""
    Dim myItems As SPListItemCollection = list.GetItems(query)

    Dim item As SPListItem
    For Each item In myItems
        Response.Write((SPEncode.HtmlEncode(item("Name")) + "<BR>"))
    Next item
Finally
    webSite.Dispose()
End Try
using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"])
{
    SPList oList = oWebsite.Lists["DocLib_Name"];
    SPView oView = oList.Views["View_Name"];

    SPQuery oQuery = new SPQuery(oView);
    oQuery.ViewAttributes = "Scope=\"Recursive\"";
    SPListItemCollection collListItemsAvailable = 
      oList.GetItems(oQuery);

    foreach (SPListItem oListItemAvailable in collListItemsAvailable)
    {
        Response.Write(SPEncode.HtmlEncode(oListItemAvailable["Name"]) + 
          "<BR>");
    }
}
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects

請參閱

參照

SPQuery class

SPQuery members

Microsoft.SharePoint namespace