CAML query result on SharePoint library not showing folders data?

Posted on 2012-04-04
Medium Priority
Last Modified: 2012-04-05
Hi, I am writing a code to retrieving files from SharePoint library based on properties value using CAML query, below is the code:
SPList mylist = myWeb.Lists["MIS"]; //MIS is the SharePoint library
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Domain'/><Value Type='Text'>External</Value></Eq></Where>";
SPListItemCollection items = mylist.GetItems(query);
foreach (SPListItem item in items)
{ Response.Write(SPEncode.HtmlEncode(item["Title"].ToString()) + "<BR>"); }  
Above code is showing only first level of files means if files are uploaded within folders then that files are not coming in result.

Can anyone help me to get folders data also.
Question by:Minesh Shah
LVL 18

Accepted Solution

ivan_vagunin earned 2000 total points
ID: 37807565

Add following before GetItems():
query.ViewAttributes = "Scope=\"Recursive\"";
This will make query items in all subfolders.
LVL 10

Author Closing Comment

by:Minesh Shah
ID: 37815182
done, working

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
Article by: Shaun
Tiling windows is a great way to see multiple applications at once. Windows Tiler is a tool that automatically tiles open application windows as the open and close.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Watch the video of Kernel Migrator for SharePoint, which demonstrate the process easily of migration from SharePoint to SharePoint, OneDrive for Business & Google Drive servers, Public Folder to SharePoint, File Server to SharePoint. The tool has va…

586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question