I working in a old-style-documents-archive-web-part-implementation that means I have a document library with folders and sub-folder.
I start to say you that I don’t like this solution and I think that use the Managed metada server is a better solution, but anyway if you need to do queries in a document library you have to ways.
If you use SPQuery you need to specify the properties ViewAttributes :
SPQuery query = new SPQuery();
query.ViewAttributes = "Scope=\"RecursiveAll\"";
Instead if you use LinqToSharePoint you can use the property ScopeToFolder:
var q = dc.MyDocs.ScopeToFolder("", true).Where(p => p.DueDate < DateTime.Now.AddMonths(1));
In the MSDN page we can find the following parameters explanation:
public IQueryable<TEntity> ScopeToFolder( string folderUrl, bool recursive )
folderUrl –> The URL of the folder.
recursive –> true to include items in subfolders; false to exclude them.