Programmatically reading contents of Files inside folders in Document Library and display in to gridview in MOSS 2007
-
Tuesday, May 01, 2012 3:47 PM
Hi,
I have multiple folders in SharePoint document library(MOSS 2007), each of the folders contains multiple files. My requirement is to get all files :Title, Name , Modified Date, Modified By and to display in to grid view.I was using CAML query but not able to get the files name inside the folder only folders name are returning as a query result. Please help.
All Replies
-
Tuesday, May 01, 2012 4:21 PM
//Try this
<ViewScope='Recursive'> <Query> <Where> ... </Where> <QueryOptions> <ViewAttributes Scope='Recursive' /> </QueryOptions> <RowLimit>100</RowLimit> </Query> </View>
-Sangeetha
-
Monday, May 07, 2012 9:30 AM
Hi Ravi,
In you CAML query, you should set
Query.ViewAttributes = "Scope=\"RecursiveAll\"";For example:
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>"); } }For more information, please refer to:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewattributes.aspx
Thanks,
SimonSimon Huang
TechNet Community Support
- Proposed As Answer by Christopher ClementEditor Monday, May 07, 2012 9:33 AM
- Marked As Answer by Shimin Huang Friday, May 11, 2012 6:42 AM
-
Monday, May 07, 2012 9:49 AM
Hi,
I have come across the same requirement.I blogged it.
Looping all folders and retrieve the file name
You need to put one more foreach loop inside the SPFolder to loop all the files inside.
Murugesa Pandian.,MCTS|App.Devleopment|Configure
- Edited by Murugesa Pandian Monday, May 07, 2012 9:51 AM
- Marked As Answer by Shimin Huang Friday, May 11, 2012 6:42 AM

