xiaolizi007
1/16/2017 - 2:58 AM

SPQuery Demo

SPQuery #sharepoint

string joins = "<Join Type='LEFT' ListAlias='Systems'><Eq><FieldRef Name='System' RefType='Id' /><FieldRef List='Systems' Name='ID' /></Eq></Join>";
string projectedFields = "<Field Name='AppName' Type='Lookup' List='Systems' ShowField='AppName' /><Field Name='ShortName' Type='Lookup' List='Systems' ShowField='ShortName' />";
string viewfields = "<FieldRef name='ReferenceName' /><FieldRef name='ReferenceLink' /><FieldRef Name='AppName' /><FieldRef Name='ShortName' />";
string query = string.Format("<Where><Eq><FieldRef Name='ShortName' /> <Value Type='Text'>{0}</Value></Eq></Where>", Application);
 
var spQuery = new SPQuery();
spQuery.Joins = joins;
spQuery.Query = query;
spQuery.ViewFields = viewfields;
spQuery.ProjectedFields = projectedFields;
var items = sourceList.GetItems(spQuery);

SPWeb web = new SPSite("http://nick").OpenWeb("test");  //Open website

web.AllowUnsafeUpdates = true;

SPList list = web.Lists["ListName"];

SPQuery query = new SPQuery();

query.Query = "<Where>"+
          "<And><And>"+
          "<Eq><FieldRef Name=\"Filed_1\"/><Value Type=\"Text\">Test</Value></Eq>" +
          "<Eq><FieldRef Name=\"Filed_2\"/><Value Type=\"Text\">" + (string)OneValue + "</Value></Eq>" +
          "</And>"+
          "<Eq><FieldRef Name=\"Filed_3\"/><Value Type=\"Text\">" + (string)TwoValue + "</Value></Eq>" +
          "</And>"+
          "</Where>";

query.RowLimit = 10;

//查询
SPListItemCollection items = list.GetItems(query);