Scenario : Sharepoint 2010 foundation site with a document library. The library has many folders (and probably sub-folders in each folder). There are files in these folders/sub-folders.

I am looking to get all the filenames that have certain criteria (ex: begins with "MYFILE").

so two questions here

a) How to traverse through every folder (and sub-folder) to find the filename. All I am bothered about is the filename but when I show them I would like to provide hyperlink such that they can click on it.

b) I would like to show all the files from the search in a kind of gridview. What's the best approach.

I need to deploy this on a out-of-box ASPX page which has no ".cs" associated to it.


2 Answers 2


Create a view in the document library with all the desired columns, set a filter Name Begins with MyFile and set the folder options to show all files without folders. If you have many thousands of documents, be sure to page the results through the view configuration. When done, click OK to save it and distribute that URL and it will show the contents automatically filtered by the file name.

  • I would like to achieve this through code. Reason is the files I am looking for depends on various condition. Please suggest with an coding or development ideas.
    – Anirudh
    Aug 11, 2011 at 15:30
  • What type of code? I'm not a developer, but I could probably come up with a jQuery/SPServices approach. Aug 15, 2011 at 12:07

Are your document library already created? I'm asking because creating large hierarchies in SharePoint document libraries in general are considered a bad practice, and there often are better ways to structure your documents.

By creating folders you really havent mooved away from the paradigm of a share on a network drive with deep nested folder hierarchies. That you are having trouble finding your data in SharePoint is proof already that your findability is very low!

Consider using meta data to categorize your files instead, then either (if using SP2010) use Meta Navigation or Key Filters for filtering your current view, or create views that filters on your meta data.

Further reading:
Just say No to folders Folder-Less SharePoint paradigm.
Convert Folder Structures to meta data

  • I would like to use the Meta navigation approach. But here is the situation. Users upload the documents and they do create sub-folders as they wish (I can train them not to do so). I have to write some webpart reading those files for some matching condition which varies for every click on the page. Sometimes I have to show files starting with "NY" and sometimes "CA" and so on.
    – Anirudh
    Aug 11, 2011 at 15:31
  • You can disable folders on any document library, so you can enforce this if you want. I still think you should consider metadata when planning how the webpart should work :) Aug 11, 2011 at 17:41
  • Can you give any webpart examples related to metadata and specific to my issue? Appreciate your inputs. Thanks
    – Anirudh
    Aug 11, 2011 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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