Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

SPQuery.ViewAttributes Property

Windows SharePoint Services 3

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

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

public string ViewAttributes { get; set; }

Property Value

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

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.

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.

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 = 

    foreach (SPListItem oListItemAvailable in collListItemsAvailable)
        Response.Write(SPEncode.HtmlEncode(oListItemAvailable["Name"]) + 

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 Best Practices: Using Disposable Windows SharePoint Services Objects.

Community Additions

© 2015 Microsoft