SPSiteDataQuery 格式,其实下面的是很不规范的,只是让自己了解其真正的格式。以后会弄一个类来做这方面的工作
<MatchingQuery> <Lists><List ID="2DF16909-AEE4-44F0-BBF5-B6E5F33F7AD6" /></Lists> <Webs Scope="SiteCollection" /> <Query> <OrderBy><FieldRef Name='ID'/></OrderBy> <Where> <And><And><And> <IsNotNull><FieldRef Name="_x0030_03aab56_x002d_bb26_x002d_4815_x002d_83d2_x002d_335e857a36f8" /></IsNotNull> <Eq><FieldRef Name="_x007b_634f940a_x002d_e3d8_x002d_47d3_x002d_998f_x002d_1f6cf85d6954_x007d_" /><Value Type="DateTime"><Today OffsetDays="1" /></Value></Eq> </And> <Or><Or> <Eq><FieldRef Name="_x007b_b65db77a_x002d_0c3d_x002d_45fb_x002d_8a79_x002d_ab4ff9bca304_x007d_" /><Value Type="Text">Hire</Value></Eq> <Eq><FieldRef Name="_x007b_b65db77a_x002d_0c3d_x002d_45fb_x002d_8a79_x002d_ab4ff9bca304_x007d_" /><Value Type="Text">Rehire</Value></Eq> </Or> <Eq><FieldRef Name="_x007b_b65db77a_x002d_0c3d_x002d_45fb_x002d_8a79_x002d_ab4ff9bca304_x007d_" /><Value Type="Text">Transfer</Value></Eq> </Or> </And> <Or> <Eq><FieldRef Name="_x007b_136c33c4_x002d_c3fa_x002d_457b_x002d_8640_x002d_06c403f596f2_x007d_" /><Value Type="Text">Notified</Value></Eq> <Eq><FieldRef Name="_x007b_136c33c4_x002d_c3fa_x002d_457b_x002d_8640_x002d_06c403f596f2_x007d_" /><Value Type="Text">Processed</Value></Eq> </Or></And> </Where></Query> <ViewFields><FieldRef Name="Company"/><FieldRef Name="Location"/><FieldRef Name="_x007b_b65db77a_x002d_0c3d_x002d_45fb_x002d_8a79_x002d_ab4ff9bca304_x007d_"/><FieldRef Name="FileRef"/><FieldRef Name="EncodedAbsUrl"/></ViewFields> </MatchingQuery>
操作:
public SPSiteDataQuery MatchingQuery { get { SPSiteDataQuery oQuery = null; try { XmlNode xQuery = dJob.MatchingQuery; oQuery = new SPSiteDataQuery(); //Changed to solve feature not installed issue. //oQuery.Lists = "<Lists BaseType='1'/>"; oQuery.Lists = xQuery.SelectSingleNode("Lists").OuterXml; oQuery.Webs = xQuery.SelectSingleNode("Webs").OuterXml; oQuery.Query = xQuery.SelectSingleNode("Query").InnerXml; oQuery.ViewFields = xQuery.SelectSingleNode("ViewFields").InnerXml; } catch (Exception ex) { Log.JobErrorWrite(Name, "Job: MatchingQuery", ex.ToString()); } return oQuery; } } Applicator: private DataTable GetMatchItems(SPWeb Web) { DataTable DT = null; try { SPSiteDataQuery oQuery = JobInfo.MatchingQuery; DT = Web.GetSiteData(oQuery); } catch(Exception ex) { Log.JobErrorWrite(Title, "Reminder: GetMatchItems", ex.ToString()); } return DT; }
SPQuery:
SPQuery:
public SPListItemCollection GetItems(SPList List, string QueryString)
{
SPQuery Query = null;
SPListItemCollection ItemCollection = null;
try
{
Query = new SPQuery();
Query.Query = QueryString;
ItemCollection = List.GetItems(Query);
}
catch (Exception ex)
{
Log.JobErrorWrite(_JobName, "ListOperator: GetItems", ex.ToString());
}
return ItemCollection;
}
Operator:
string query = "<Where><Eq><FieldRef Name=\"JobStatus\" /><Value Type=\"Choice\">Activating</Value></Eq></Where>";
ListOperator oListOperator = new ListOperator(string.Empty);
SPListItemCollection ItemCollection = oListOperator.GetItems(list, query);
OR
SPQuery query = new SPQuery();
query.Query = string.Concat(
"<Where><Eq>",
"<FieldRef Name='Status'/>",
"<Value Type='CHOICE'>Not Started</Value>",
"</Eq></Where>",
"<OrderBy>",
"<FieldRef Name='DueDate' Ascending='TRUE' />",
"<FieldRef Name=’Priority’ Ascending='TRUE' />",
"</OrderBy>");
query.ViewFields = string.Concat(
"<FieldRef Name='AssignedTo' />",
"<FieldRef Name='LinkTitle' />",
"<FieldRef Name='DueDate' />",
"<FieldRef Name='Priority' />");
// Get data from a list.
string listUrl = web.ServerRelativeUrl + "/lists/tasks";
SPList list = web.GetList(listUrl);
SPListItemCollection items = list.GetItems(query);