Condividi tramite


SPQuery.ViewAttributes Property

Gets or sets the attributes of the view used in the query.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Property ViewAttributes As String
    Get
    Set
'Usage
Dim instance As SPQuery
Dim value As String

value = instance.ViewAttributes

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

Property Value

Type: System.String
A string that contains the view attributes.

Remarks

The ViewAttributes property contains attributes of the View element that is used in Collaborative Application Markup Language. For example, if the Scope attribute is set to Recursive (Scope="Recursive"), the query displays all the files within a document library, including ones in subfolders. If it is set to anything else, the query displays only files in the top folder.

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.

Examples

The following code example sets a recursive scope for a query and displays all files contained within a specified document library.

This example requires using directives (Imports in Microsoft Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

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>");
    }
}

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

SPQuery Class

SPQuery Members

Microsoft.SharePoint Namespace