only My site

Monday, October 29, 2012

Read All the files (including Sub Folder) in a List

Read the required list item directly using CAML query. You can search for a list item inside folders by setting Scope attribute to Recursive as follows:

        SPWeb web = SPContext.Current.Web;
        SPList list = web.Lists["Shared Documents"];
        string content = string.Empty;
           
        SPQuery query = new SPQuery();
        query.ViewAttributes = "Scope=\"Recursive\"";
        query.Query = "<Where><Eq><FieldRef Name='FileLeafRef' />
            <Value Type='File'>NewProcess.js</Value></Eq></Where>";
        SPListItemCollection items = list.GetItems(query);
        SPListItem item = items[0];

No comments: