本文整理汇总了C#中SPList.GetItems方法的典型用法代码示例。如果您正苦于以下问题:C# SPList.GetItems方法的具体用法?C# SPList.GetItems怎么用?C# SPList.GetItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPList
的用法示例。
在下文中一共展示了SPList.GetItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BatchDeleteItems
public static void BatchDeleteItems(SPList splTask, SPQuery query,SPWeb web)
{
// Set up the variables to be used.
StringBuilder methodBuilder = new StringBuilder();
string batch = string.Empty;
string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Batch onError=\"Return\">{0}</Batch>";
string methodFormat = "<Method ID=\"{0}\">" +
"<SetList Scope=\"Request\">{1}</SetList>" +
"<SetVar Name=\"ID\">{2}</SetVar>" +
"<SetVar Name=\"Cmd\">Delete</SetVar>" +
"</Method>";
// Get the list containing the items to update.
//PList list = WorkFlowUtil.GetWorkflowList(listName);
// Query to get the unprocessed items.
SPListItemCollection unprocessedItems = splTask.GetItems(query);
// Build the CAML delete commands.
foreach (SPListItem item in unprocessedItems)
{
methodBuilder.AppendFormat(methodFormat, "1", item.ParentList.ID, item.ID.ToString());
}
// Put the pieces together.
batch = string.Format(batchFormat, methodBuilder.ToString());
// Process the batch of commands.
string batchReturn = web.ProcessBatchData(batch.ToString());
}
示例2: GetListItemCollection
internal SPListItemCollection GetListItemCollection(SPList spList, string keyOne, string valueOne, string keyTwo, string valueTwo, string keyThree, string valueThree)
{
// Return list item collection based on the lookup field
SPField spFieldOne = spList.Fields[keyOne];
SPField spFieldTwo = spList.Fields[keyTwo];
SPField spFieldThree = spList.Fields[keyThree];
var query = new SPQuery
{
Query = @"<Where>
<And>
<And>
<Eq>
<FieldRef Name=" + spFieldOne.InternalName + @" />
<Value Type=" + spFieldOne.Type.ToString() + @">" + valueOne + @"</Value>
</Eq>
<Eq>
<FieldRef Name=" + spFieldTwo.InternalName + @" />
<Value Type=" + spFieldTwo.Type.ToString() + @">" + valueTwo + @"</Value>
</Eq>
</And>
<Eq>
<FieldRef Name=" + spFieldThree.InternalName + @" />
<Value Type=" + spFieldThree.Type.ToString() + @">" + valueThree + @"</Value>
</Eq>
</And>
</Where>"
};
return spList.GetItems(query);
}
示例3: CleanList
private static void CleanList(SPList list)
{
if (list == null)
throw new ArgumentNullException("list");
SPQuery spQuery = CreateGetAllItemsQuery();
int batchNumber = 1;
while (true)
{
// get ids of items to be deleted
SPListItemCollection items = list.GetItems(spQuery);
if (items.Count <= 0)
break;
string batchDeleteXmlCommand = GetBatchDeleteXmlCommand(list, items);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
RunDeleteBatch(list, batchDeleteXmlCommand);
stopwatch.Stop();
Console.WriteLine(string.Format("Processed batch #{0} of {1} items in {2} second(s)", batchNumber, BatchSize, stopwatch.ElapsedMilliseconds / 1000.0));
batchNumber++;
}
}
示例4: CheckandAddEntry
public static void CheckandAddEntry(SPList configurationList, Guid ProjectGuid, Project Project_Svc)
{
try
{
// Checking whether the project id is already available.
var query = new SPQuery
{
Query =
@"<Where><Eq><FieldRef Name='" + ProjectUIDFieldName + "' /><Value Type='Text'>" + ProjectGuid.ToString() + "</Value></Eq></Where>"
};
var ProjectItemCollection = configurationList.GetItems(query);
if (ProjectItemCollection.Count == 0)
{
configurationList.ParentWeb.Site.RootWeb.AllowUnsafeUpdates = true;
SPListItem item = configurationList.Items.Add();
//first project name
item["Title"] = Project_Svc.GetProjectNameFromProjectUid(ProjectGuid, DataStoreEnum.WorkingStore);
item[GroupFieldName] = DefaultGroupValue;
item[ProjectUIDFieldName] = ProjectGuid.ToString();
item.Update();
configurationList.ParentWeb.Site.RootWeb.Update();
}
}
catch (Exception ex)
{
ErrorLog("Error at adding configuration item to the list due to " + ex.Message, EventLogEntryType.Error);
}
}
示例5: Execute
// Executes the expression tree that is passed to it.
internal static object Execute(SPList list, Expression expression, bool isEnumerable)
{
// The expression must represent a query over the data source.
if (!IsQueryOverDataSource(expression))
throw new InvalidProgramException("No query over the data source was specified.");
var caml = (new CamlTranslator()).Translate(null, expression);
var query = new SPQuery();
var viewFieldsXml = caml.Element(Tags.ViewFields);
var rowLimitXml = caml.Element(Tags.RowLimit);
var queryXml = caml.Elements()
.Where(n => n.Name != Tags.ViewFields && n.Name != Tags.RowLimit)
.ToList();
query.Query = (new XElement(Tags.Query, queryXml)).Value;
if (viewFieldsXml != null)
{
query.ViewFields = viewFieldsXml.Value;
query.ViewFieldsOnly = true;
}
if (rowLimitXml != null)
{
query.RowLimit = (int)rowLimitXml.Value;
}
return list.GetItems(query);
}
示例6: GenerateValidImageName
public static string GenerateValidImageName(string fileName, SPList pictureLibrary)
{
//Check if new image name validates
int i = 0;
string temp = fileName;
string extention = Path.GetExtension(fileName);
SPQuery query = new SPQuery(pictureLibrary.DefaultView);
SPListItemCollection imageCollection;
do
{
i++;
query.ViewFields = "<Where><Eq><FieldRef Name='LinkFilename' /><Value Type='Computed'>" + fileName + "</Value></Eq></Where>";
imageCollection = pictureLibrary.GetItems(query);
if (imageCollection.Count > 0)
{
fileName = temp;
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName) + " " + i;
fileName = fileNameWithoutExtension + extention;
}
else {
break;
}
} while (imageCollection.Count > 0);
return fileName;
}
示例7: GetCostsFromMonth
private static SPListItemCollection GetCostsFromMonth(SPList costs, SPListItemCollection delegationsForSelectedMonth)
{
StringBuilder delegationIDBuilder = new StringBuilder();
foreach (SPListItem delegationItem in delegationsForSelectedMonth)
{
delegationIDBuilder.AppendFormat("<Value Type='Lookup'>{0}</Value>", delegationItem["ID"]);
}
string costsForSelectedDelagationsQueryString = string.Format(
"<Where>" +
"<In>" +
"<FieldRef Name='{0}' LookupId='TRUE'/>" +
"<Values>" +
"{1}" +
"</Values>" +
"</In>" +
"</Where>",
DelegationsFields.Delegation.Name,
delegationIDBuilder);
SPQuery costsForSelectedDelegationsQuery = new SPQuery();
costsForSelectedDelegationsQuery.Query = costsForSelectedDelagationsQueryString;
SPListItemCollection monthlyCosts = costs.GetItems(costsForSelectedDelegationsQuery);
return monthlyCosts;
}
示例8: GetValue
private SPListItem GetValue(SPWeb web, SPList list, string keyStr, ref int returnValue)
{
SPQuery spQueryConfig = new SPQuery
{
Query = "<Where>" +
"<Eq><FieldRef Name='Title' /><Value Type='Text'>" + keyStr + "</Value></Eq>" +
"</Where>",
RowLimit = 1
};
var configItems = list.GetItems(spQueryConfig);
if (configItems != null && configItems.Count > 0)
{
try
{
int diff = DateTime.Now.DayOfWeek - DayOfWeek.Monday;
if (diff < 0)
{
diff += 7;
}
var startWeekDate = DateTime.Now.AddDays(-1 * diff).Date;
var dateModified = Convert.ToDateTime(Convert.ToString(configItems[0]["Modified"]));
if (keyStr.Equals("YesterdayNumBer") && dateModified.Date < DateTime.Now.Date)
{
var itemToUpdate = configItems[0];
var yNumber = GetValue(list, "DayNumBer");
itemToUpdate["Value"] = yNumber;
web.AllowUnsafeUpdates = true;
itemToUpdate.Update();
returnValue = yNumber;
return configItems[0];
}
if (keyStr.Equals("DayNumBer") && dateModified.Date < DateTime.Now.Date)
{
returnValue = 1;
return configItems[0];
}
if (keyStr.Equals("WeekNumBer") && dateModified.Date < startWeekDate)
{
returnValue = 1;
return configItems[0];
}
if (keyStr.Equals("MonthNumBer") && dateModified.Date < (new DateTime(DateTime.Now.Year,DateTime.Now.Month,1)).Date)
{
returnValue = 1;
return configItems[0];
}
returnValue = Convert.ToInt32(configItems[0]["Value"]);
return configItems[0];
}
catch (SPException) { }
catch (Exception) { }
}
returnValue = 1;
return null;
}
示例9: GetOrderLines
private static void GetOrderLines(SPList orderLineList, SalesOrder salesOrder)
{
var lineQuery = new SPQuery();
lineQuery.Query = "<Where><Eq><FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >" + salesOrder.SalesOrderId + "</Value></Eq></Where>";
var orderLines = orderLineList.GetItems(lineQuery);
foreach (SPListItem line in orderLines)
{
salesOrder.Lines.Add(new OrderLine { Product = line.Title, Price = (double)line["Price"], Quantity = Convert.ToInt32(line["Quantity"]) });
}
}
示例10: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
currentList = SPContext.Current.Web.Lists[new Guid(Context.Request["List"])];
SPView defView = currentList.DefaultView;
items = currentList.GetItems(defView);
if (!Page.IsPostBack)
PopulatePage();
this.TemplatesList.SelectedIndexChanged += new EventHandler(TemplatesList_SelectedIndexChanged);
this.DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(ImageButton1_Click);
}
示例11: generataSliderHTML
private void generataSliderHTML(StringBuilder sb, SPList list, int lcid)
{
SPQuery oQuery = new SPQuery();
SPListItemCollection collListItems;
oQuery.Query = "<Where><IsNotNull><FieldRef Name='ID'/></IsNotNull></Where>" +
"<OrderBy><FieldRef Name='ItemOrder' /></OrderBy>";
collListItems = list.GetItems(oQuery);
if (sb != null & list != null && list.Items.Count > 0)
{
sb.Append("<div class=\"span-2\"> ");
int i = 1;
sb.Append("<ul class=\"list-bullet-none\">");
foreach (SPListItem item in collListItems)
{
if (i <= 3)
{
if (i == 1 && lcid == 1033)
//--sb.Append("<li class=\"personLinkRow\"><div class= \"float-left\">" + item["English Link Text"] + "</br><a style=\"color: white !important;\" href=\"" + item["English Url"] + "\"> </div><div class=\"align-right\">" + "<img class=\"float-right\" height: 45px;\" src=\"" + item.File.ServerRelativeUrl + "\" /> </a>");
//if (i == 2 && lcid == 1033)
sb.Append("<a style=\"color: white !important;\" href=\"" + item["English Url"] + "\"> <li class=\"webLinkRow\"><div class= \"float-left\">" + item["English Link Text"] + "</br><b>" + item["English Description"] + "</b></div><div class=\"align-right\">" + "<img class=\"float-right\" src=\"" + item.File.ServerRelativeUrl + "\" />");
if (i == 2 && lcid == 1033)
sb.Append("<a style=\"color: white !important;\" href=\"" + item["English Url"] + "\"> <li class=\"phoneLinkRow\"><div class= \"float-left\">" + item["English Link Text"] + "</br><b>" + item["English Description"] + "</b></div><div class=\"align-right\">" + "<img class=\"float-right sideImageLinksSizes\" src=\"" + item.File.ServerRelativeUrl + "\" />");
if (i == 3 && lcid == 1033)
sb.Append("<a style=\"color: white !important;\" href=\"" + item["English Url"] + "\"> <li class=\"notepadLinkRow\"><div class= \"float-left\">" + item["English Link Text"] + "</br><b>" + item["English Description"] + "</b></div><div class=\"align-right\">" + "<img class=\"float-right\" src=\"" + item.File.ServerRelativeUrl + "\" />");
else
{
if (i == 1 && lcid == 1036)
//--sb.Append("<li class=\"personLinkRow\"><div class= \"float-left\">" + item["French Link Text"] + "</br><a style=\"color: white !important;\" href=\"" + item["French Url"] + "\"> </div><div class=\"align-right\">" + "<img class=\"float-right\" height: 45px;\" src=\"" + item.File.ServerRelativeUrl + "\" /></a>");
//if (i == 2 && lcid == 1036)
sb.Append("<a style=\"color: white !important;\" href=\"" + item["French Url"] + "\"> <li class=\"webLinkRow\"><div class= \"float-left\">" + item["French Link Text"] + "</br><b>" + item["French Description"] + "</b></div><div class=\"align-right\">" + "<img class=\"float-right\" src=\"" + item.File.ServerRelativeUrl + "\" />");
if (i == 2 && lcid == 1036)
sb.Append("<a style=\"color: white !important;\" href=\"" + item["French Url"] + "\"> <li class=\"phoneLinkRow\"><div class= \"float-left\">" + item["French Link Text"] + "</br><b>" + item["French Description"] + "</b></div><div class=\"align-right\">" + "<img class=\"float-right sideImageLinksSizes\" src=\"" + item.File.ServerRelativeUrl + "\" /><");
if (i == 3 && lcid == 1036)
sb.Append("<a style=\"color: white !important;\" href=\"" + item["French Url"] + "\"> <li class=\"notepadLinkRow\"><div class= \"float-left\">" + item["French Link Text"] + "</br><b>" + item["French Description"] + "</b></div><div class=\"align-right\">" + "<img class=\"float-right\" src=\"" + item.File.ServerRelativeUrl + "\" />");
}
sb.Append("</li> </a> <div class=\"clear\" class=\"sideImageLinksBottomClear;\"></div>");
i++;
}
else
break;
}
sb.Append("</ul>");
sb.Append("</div>");
}
}
示例12: FindListItem
protected override SPListItem FindListItem(SPList list, SPFolder folder, ListItemDefinition listItemModel)
{
var definition = listItemModel.WithAssertAndCast<ComposedLookItemDefinition>("model", value => value.RequireNotNull());
// first by Name
var items = list.GetItems(new SPQuery
{
Folder = folder,
Query = string.Format(@"<Where>
<Eq>
<FieldRef Name='Name'/>
<Value Type='Text'>{0}</Value>
</Eq>
</Where>", definition.Name)
});
if (items.Count > 0)
return items[0];
// by Title?
items = list.GetItems(new SPQuery
{
Folder = folder,
Query = string.Format(@"<Where>
<Eq>
<FieldRef Name='Title'/>
<Value Type='Text'>{0}</Value>
</Eq>
</Where>", definition.Title)
});
if (items.Count > 0)
return items[0];
return null;
}
示例13: GetListItemCollection
internal SPListItemCollection GetListItemCollection(SPList spList, string key, string value)
{
// Return list item collection based on the lookup field
SPField spField = spList.Fields[key];
var query = new SPQuery
{
Query = @"<Where>
<Eq>
<FieldRef Name='" + spField.InternalName + @"'/><Value Type='" + spField.Type.ToString() + @"'>" + value + @"</Value>
</Eq>
</Where>"
};
return spList.GetItems(query);
}
示例14: GetLookFieldIDS
public static SPFieldLookupValueCollection GetLookFieldIDS(string lookupValues, SPList lookupSourceList)
{
SPFieldLookupValueCollection lookupIds = new SPFieldLookupValueCollection();
string[] lookups = lookupValues.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string lookupValue in lookups)
{
SPQuery query = new Microsoft.SharePoint.SPQuery();
query.Query = String.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", lookupValue);
SPListItemCollection listItems = lookupSourceList.GetItems(query);
foreach (Microsoft.SharePoint.SPListItem item in listItems)
{
SPFieldLookupValue value = new SPFieldLookupValue(item.ID.ToString());
lookupIds.Add(value);
break;
}
}
return lookupIds;
}
示例15: FindListItem
protected virtual SPListItem FindListItem(SPList list, SPFolder folder, ListItemDefinition listItemModel)
{
var items = list.GetItems(new SPQuery
{
Folder = folder,
Query = string.Format(@"<Where>
<Eq>
<FieldRef Name='Title'/>
<Value Type='Text'>{0}</Value>
</Eq>
</Where>", listItemModel.Title)
});
if (items.Count > 0)
return items[0];
return null;
}