I am using code like the following to get a list of all documents in a site with SPSiteDataQuery however, it is returning all sorts of documents that were not uploaded by the user. What is the best way to filter the list to only those documents that a user would have uploaded?
I am suspecting that there is a query that I can use but I am not sure what FieldRef I should be using to find only user uploaded documents (not hidden or system type document files).
see *** below in the method
thanks
protected DataTable GetListDataSPSiteDataQuery(string siteUrl, bool recursive, ref string error) {
DataTable results = null;
using (SPSite site = new SPSite(siteUrl)) {
SPWeb web = site.OpenWeb();
SPSiteDataQuery query = new SPSiteDataQuery();
//query.Webs = "<Webs Scope='SiteCollection' />"; //query all web sites in site collection
if (recursive)
query.Webs = "<Webs Scope='Recursive' />";
query.Lists = "<Lists ServerTemplate='101' Hidden='FALSE' MaxListsLimit='0' />";
//query.Lists = "<Lists BaseType='1' MaxListsLimit='0' />"; //document library only (0=generic list, 1=doc library,3=discussino forum,4-vote or survey,5=issues list)
// *** can i provide a query here to filter for the documents i am interested in?
query.Query = string.Empty;
//query.Query = "<Where>" +
// "<Gt>" +
// "<FieldRef Name='File_x0020' />" +
// "<Value Type='Number'>0</Value>" +
// "</Gt>开发者_运维百科;" +
// "</Where>";
query.ViewFields = _viewFields;
results = web.GetSiteData(query);
}
return results;
}
I'm not on the office right now to test but try adding the following fields to the result (so you can see if they create a filterable pattern)
- ContentType (look for the obnoxious ones, like _Hidden)
- CreatedBy (Author should be SHAREPOINT\system for non-user files)
I will try to get a test going if this doesn't help, but I do not think there's the big elephant in the room that says ONLY_USER_CREATED besides those properties. If the "all sorts of documents not uploaded by the user" are ONLY the /forms/ folder files (AllItems.aspx, EditItem.aspx etc) it can probably be worked around with a few Contains tests.
Feature like CAML query builder will help you build valid queries.
Try:
query.Query = @"<Where>
<Eq>
<FieldRef Name='Author' />
<Value Type='User'>Bob Smith</Value>
</Eq>
</Where>";
精彩评论