Is it possible to get all files by content type in the whole site collection? This is the code I currently have:
//Get list of subsites to traverse
List<string> subsites = getSubSiteList();
foreach (string siteUrl in subsites)
{
using (SPWeb web = new SPSite(siteUrl).OpenWeb())
{
if (web.GetFolder("Pages").Exists)
{
//Get Pages Folder from subsite
SPFolder folderCol = web.Folders["Pages"];
//Set files in Pages folder
SPFileCollection fileCol = folderCol.Files;
foreach (SPFile file in fileCol)
{
//Debug.WriteLine("File in site: " + siteUrl + " file: " + file.Name);
}
}
web.Dispose();
}
}
In this code I am iterating through all the subsites and going to the “Pages” folder to get a certain page, but I would like to be able to just pull all these files without having to go through each subsite, and getting it by content-type instead of going inside the “Pages” folder and parsing from there. How would the code look? Thanks!
What you’re looking for is a site data query.
Other options would be to programmatically leverage the search functionality, but I don’t think it’s as good as an option; the site data query is literally designed for exactly this.