SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

By request I'm developing a custom WebPart where it's possible for the user to search files and folders inside a document library, i made a GridView to list the files (working ok I'm not searching), a TextBox for input and a button.

My document library structure is something like this:

  • Document Library
    • Child Folder 1
    • Child Folder 2
      • Grand Child Folder
      • Image.jpg

When using the search I created, I type the name 'Image'. But it always returns nothing (SPListItemCollection.count is always 0).

For the search, i'm using the following code:

SPQuery query = new SPQuery();

query.ViewAttributes = "Scope='RecursiveAll'";

String caml = @"<Where>
                      <FieldRef Name='Title' />
                      <Value Type='Text'>{0}</Value>
                  <FileRef Name='ID' Ascending='True' />

query.Query = String.Format(caml, "Image");
SPListItemCollection resultGetItems = list.GetItems(query);

Anyone can help me with this one? i can't seem to get it working.

Thanks a lot.

share|improve this question
Have you set the title of the file? Usually it's the name that is set, so you have to use FileLeafRef as the name in the FieldRef – Per Jakobsen Oct 8 '12 at 20:09
That did it. Thanks a lot!!! I was almost getting there, I saw it was returning a exception on the title right after i posted, but didn't think of the FileLeafRef attribute. Thanks a bunch. – C. Hoffmann Oct 8 '12 at 20:21
up vote 2 down vote accepted

Please try modifying the title to "FileLeafRef" in the query.

The internal Column name inside the folder is "FileLeafRef".

Please see the below link:

Please Let me know if it works for you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.