本文整理汇总了C#中SPList.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# SPList.AddItem方法的具体用法?C# SPList.AddItem怎么用?C# SPList.AddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPList
的用法示例。
在下文中一共展示了SPList.AddItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOrderLine
private static void AddOrderLine(SPList orderLineList, OrderLine line)
{
var orderLine = orderLineList.AddItem();
orderLine["Title"] = line.Product;
orderLine["Price"] = line.Price;
orderLine["Quantity"] = line.Quantity;
orderLine.Update();
}
示例2: AddSalesOrderHeader
private static void AddSalesOrderHeader(SalesOrder order, SPList salesOrderList)
{
var salesOrder = salesOrderList.AddItem();
salesOrder["Title"] = order.Customer.Name + "_" + order.OrderDate.ToString("yyyy-MM-dd");
salesOrder["OrderDate"] = order.OrderDate;
salesOrder["Status"] = order.Status.ToString();
salesOrder["Customer"] = order.Customer.CustomerId;
salesOrder.Update();
}
示例3: AddNew
public static int AddNew(SPList list, int klientId, int rok, string key)
{
Debug.WriteLine("BLL.tabStratyZLatUbieglych.AddNew: " + key);
SPListItem nItem = list.AddItem();
BLL.Tools.Set_Index(nItem, "selKlient", klientId);
BLL.Tools.Set_Index(nItem, "colRokObrachunkowy", rok);
BLL.Tools.Set_Text(nItem, "KEY", key);
nItem.Update();
Debug.Write("-dodany");
return nItem.ID;
}
示例4: AddDefaultData
public void AddDefaultData(SPList list)
{
var defaultDataRows = listInstance.Descendants(ns + "Data").Descendants(ns + "Rows").Descendants(ns + "Row");
foreach (var row in defaultDataRows)
{
var item = list.AddItem();
var fields = row.Descendants(ns + "Field");
foreach (var field in fields)
{
var name = field.Attribute("Name").Value;
var value = field.Value;
var spField = list.Fields.GetFieldByInternalName(name);
item[name] = ConvertValueForFieldType(spField.Type, value);
}
item.Update();
}
}
示例5: EnsureListItem
private SPListItem EnsureListItem(SPList list, ListItemDefinition listItemModel)
{
// TODO, lazy to query
// BIG TODO, don't tell me, I know that
var currentItem = list.Items
.OfType<SPListItem>()
.FirstOrDefault(i => i.Title == listItemModel.Title);
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentItem,
ObjectType = typeof(SPListItem),
ObjectDefinition = listItemModel,
ModelHost = list
});
if (currentItem == null)
{
var newItem = list.AddItem();
newItem["Title"] = listItemModel.Title;
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = newItem,
ObjectType = typeof(SPListItem),
ObjectDefinition = listItemModel,
ModelHost = list
});
newItem.Update();
return newItem;
}
else
{
currentItem["Title"] = listItemModel.Title;
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioned,
Object = currentItem,
ObjectType = typeof(SPListItem),
ObjectDefinition = listItemModel,
ModelHost = list
});
currentItem.Update();
return currentItem;
}
}
示例6: AddNews
private void AddNews(SPWeb adminWeb, SPList list, string catID, string catName, string rssLink, DataRow rss)
{
try
{
adminWeb.AllowUnsafeUpdates = true;
var item = list.AddItem();
item[FieldsName.NewsList.InternalName.Title] = rss["title"];
item[FieldsName.NewsList.InternalName.NewsUrl] = rss["link"];
item[FieldsName.NewsList.InternalName.NewsGroup] = catID;
item[FieldsName.NewsList.InternalName.NewsGroupName] = catName;
item[FieldsName.NewsList.InternalName.RSSLink] = rssLink;
var desc = Convert.ToString(rss["description"]);
var imgUrl = string.Empty;
if (desc.Contains("<img"))
{
var str = desc.Split(new string[] { "<img" }, 2, StringSplitOptions.None)[1];
desc = str.Split(new string[] { ">" }, 2, StringSplitOptions.None)[1];
str = str.Split(new string[] { ">" }, 2, StringSplitOptions.None)[0];
if (str.Contains("\""))
{
imgUrl = str.Split('\"')[1];
}
else if (str.Contains("'"))
{
imgUrl = str.Split('\'')[1];
}
else
{
str = str.Split('=')[1];
var str1 = str.Split('.')[0];
var str2 = str.Split('.')[1];
str2 = str2.Replace("/", "").Replace(" ", "").Replace("\"", "").Replace("'", "");
imgUrl = str1 + "." + str2;
}
}
item[FieldsName.NewsList.InternalName.Description] = desc.Replace("-amp;", "&").Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\"").Replace("'", "'");
if (!string.IsNullOrEmpty(imgUrl))
{
item[FieldsName.NewsList.InternalName.ImageThumb] = imgUrl;
SPFieldUrlValue imgDsp = new SPFieldUrlValue();
imgDsp.Description = item.Title;
imgDsp.Url = imgUrl;
item[FieldsName.NewsList.InternalName.ImageDsp] = imgDsp;
}
adminWeb.AllowUnsafeUpdates = true;
item.Update();
}
catch (SPException ex)
{
Utilities.LogToULS(ex);
}
}
示例7: Create_KartaKontrolna
private static int Create_KartaKontrolna(SPListItem task, string KEY, SPList list)
{
SPListItem newItem = list.AddItem();
newItem["KEY"] = KEY;
newItem["selKlient"] = Get_LookupId(task, "selKlient");
newItem["selOkres"] = Get_LookupId(task, "selOkres");
BLL.Models.Klient k = new Models.Klient(task.Web, Get_LookupId(task, "selKlient"));
Set_KartaKontrolna_InitValues(newItem, k);
//ustaw CT
if (k.TypKlienta == "KSH") newItem["ContentType"] = "Karta kontrolna KSH";
else newItem["ContentType"] = "Karta kontrolna KPiR";
newItem.SystemUpdate();
return newItem.ID;
}
示例8: CreateNewListItem
public virtual void CreateNewListItem(SPList list, SPGENRepositoryDataItem dataItem, string parentFolderRelUrl, SPGENEntityFileOperationArguments fileOperationParams)
{
SPListItem listItem;
if (string.IsNullOrEmpty(parentFolderRelUrl))
{
listItem = list.AddItem();
}
else
{
listItem = list.AddItem(GetSiteRelativeFolderUrl(list, parentFolderRelUrl), SPFileSystemObjectType.Invalid);
}
dataItem.ListItem = listItem;
}
示例9: Create_New_GFR_K
private static void Create_New_GFR_K(Microsoft.SharePoint.SPListItem item, string mask, SPList list, SPListItem klientItem)
{
string ct = "Generowanie formatek rozliczeniowych dla klienta";
int okresId = BLL.Tools.Get_LookupId(item, "selOkres");
SPListItem newItem = list.AddItem();
newItem["ContentType"] = ct;
newItem["selKlient"] = klientItem.ID;
newItem["selOkres"] = okresId;
newItem["colMaskaSerwisu"] = mask;
newItem.SystemUpdate();
}
示例10: UpdateReportForMonth
private static void UpdateReportForMonth(SPList report, DateTime reportStart, SPListItemCollection monthlyCosts)
{
double monthlySum = 0;
foreach (SPListItem cost in monthlyCosts)
{
monthlySum += (double)cost["Cost"];
}
string reportsQueryString = string.Format(
"<Where>" +
"<Eq>" +
"<FieldRef Name='{0}'></FieldRef>" +
"<Value Type='DateTime'>{1}</Value>" +
"</Eq>" +
"</Where>",
DelegationsFields.MonthIndicator.Name,
SPUtility.CreateISO8601DateTimeFromSystemDateTime(reportStart));
SPQuery monthlyReportQuery = new SPQuery();
monthlyReportQuery.Query = reportsQueryString;
SPListItemCollection monthlyReports = report.GetItems(monthlyReportQuery);
if (monthlyReports.Count > 0)
{
var item = report.GetItemById((int)(monthlyReports[0]["ID"]));
item[DelegationsFields.MonthlyCost] = monthlySum;
item.Update();
}
else
{
var item = report.AddItem();
item[DelegationsFields.MonthIndicator] = reportStart;
item[DelegationsFields.MonthlyCost] = monthlySum;
item.Update();
}
}
示例11: CreateNewBatch
private object CreateNewBatch(string batchName, SPList list)
{
SPListItem item = list.AddItem();
item["BatchName"] = batchName;
item.Update();
return item.ID;
}
示例12: useCaseAddInitialItems
}//end useCaseUpdateItems
static void useCaseAddInitialItems(SPList catsList, SPList cascomList)
{
try
{
//Console.WriteLine("NEWTRADOCTaskers Item Count = 0");
foreach(SPListItem catsListItem in catsList.Items)//iterate taskers items
{
//Console.WriteLine("CATS Item " + catsListItem);
SPListItem addNEWTRADOCTaskersItem = cascomList.AddItem();//items to add to NEWTRADOCTaskers
foreach (SPField taskersField in catsList.Fields)//iterate taskers fields
{
string getFieldTypes = taskersField.GetType().ToString();//get taskers field types
string taskersInternalName = taskersField.InternalName;//get taskers internal names
if (getFieldTypes.Contains("SPFieldText") && taskersInternalName != "_CopySource" && taskersInternalName != "_UIVersionString") //add single lines of text
{
//Copy Source/_CopySource and _UIVersionString/Version pertains to local list settings and should not copy over
//Console.WriteLine("\tCATS Field Internal Name: " + taskersField.InternalName + "\n\tCATS Display Name: " + taskersField.Title + "\n\tValue: " + catsListItem[taskersInternalName]);
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
else if (getFieldTypes.Contains("SPFieldMultiLineText"))//add miltiple lines of text fields
{
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
//Console.WriteLine("\t\t\tUpdating " + cascomField.Title);
}
else if (getFieldTypes.Contains("SPFieldChoice"))//add choice fields
{
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
else if (getFieldTypes.Contains("SPFieldBoolean") && taskersInternalName != "_HasCopyDestinations" && taskersInternalName != "_IsCurrentVersion")//add yes/no fields
{
//_HasCopyDestinations/_IsCurrentVersion pertains to local list settings
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
else if (getFieldTypes.Contains("SPFieldDateTime"))
{
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
else if (getFieldTypes.Contains("SPFieldUser"))
{
Console.WriteLine("\t" + getFieldTypes);
Console.WriteLine("\tCATS Field Internal Name: " + taskersField.InternalName + "\n\tCATS Display Name: " + taskersField.Title + "\n\tValue: " + catsListItem[taskersInternalName]);
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
}//end for
Console.WriteLine("\n Item Updated");
addNEWTRADOCTaskersItem.Update(); ;//update content database
}//end for
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.Read();
}
}//end useCaseAddItems
示例13: useCases
//.........这里部分代码省略.........
}//end for
}//end if
numberOfCASCOMAttachments = cascomAttachments.Count;
if (numberOfCASCOMAttachments == 0)//add attachments
{
Console.WriteLine("\t\tAdding CASCOM attachments.");
Console.WriteLine("\t\tNumber of CASCOMAttachments " + numberOfCASCOMAttachments);
for (int j = 0; j < catsAttachments.Count; j++)//cats attachments
{
string path = catsAttachments.UrlPrefix + catsAttachments[j];//specify relative url for file location
SPFile catsFile = webSite.GetFile(path);//cats file object
string catsFileName = catsFile.Name;//cats file name
Console.WriteLine("\t\tAdding Attachment: " + catsFileName);
byte[] binFile = catsFile.OpenBinary();//open file in binary format
cascomAttachments.Add(catsFileName, binFile);//add files to cascom item
}//end for
}//end if
}//end if*/
}//end if
}//end for taskers fields
Console.WriteLine("Updating Item.");
cascomListItem.Update();//update content database
}//end if
}//end for //taskers items
if (checkControlNumberExistsInCASCOM == false)//we are going to add items here since they do not exist in NEWTRADOC taskers
{
//Console.WriteLine("CATS Control Number DO Not EXIST in CASCOM -> " + taskersControlNumber);
SPListItem addNEWTRADOCTaskersItem = cascomList.AddItem();//items to add to NEWTRADOCTaskers
foreach (SPField taskersField in catsList.Fields)//iterate taskers fields
{
string getFieldTypes = taskersField.GetType().ToString();//get taskers field types
string taskersInternalName = taskersField.InternalName;//get taskers internal names
if (getFieldTypes.Contains("SPFieldText") && taskersInternalName != "_CopySource" && taskersInternalName != "_UIVersionString") //add single lines of text
{
//Copy Source/_CopySource and _UIVersionString/Version pertains to local list settings and should not copy over
//Console.WriteLine("\tCATS Field Internal Name: " + taskersField.InternalName + "\n\tCATS Display Name: " + taskersField.Title + "\n\tValue: " + catsListItem[taskersInternalName]);
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
else if (getFieldTypes.Contains("SPFieldMultiLineText"))//add miltiple lines of text fields
{
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
//Console.WriteLine("\t\t\tUpdating " + cascomField.Title);
}
else if (getFieldTypes.Contains("SPFieldChoice"))//add choice fields
{
//Console.WriteLine("\t" + getFieldTypes);
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
else if (getFieldTypes.Contains("SPFieldBoolean") && taskersInternalName != "_HasCopyDestinations" && taskersInternalName != "_IsCurrentVersion")//add yes/no fields
{
//_HasCopyDestinations/_IsCurrentVersion pertains to local list settings
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
}
else if (getFieldTypes.Contains("SPFieldDateTime"))
{
addNEWTRADOCTaskersItem[taskersInternalName] = catsListItem[taskersInternalName];
示例14: WriteMessage
/// <summary>
/// Writes messages of 255 characters or less
/// </summary>
/// <param name="message">The message.</param>
/// <param name="list">The list.</param>
private void WriteMessage(string message, SPList list)
{
message.RequireNotNullOrEmpty("message");
list.RequireNotNull("list");
message.Require(message.Length <= 255, "message");
SPListItem item = list.AddItem();
item["Title"] = message;
item.Update();
}
示例15: TestInit
public void TestInit()
{
using (SPSite site = new SPSite("http://sp2013test"))
{
using (SPWeb web = site.OpenWeb(webUrl))
{
TestList = web.Lists.TryGetList(this.listName);
if (TestList == null)
{
Guid listId = web.Lists.Add(this.listName, "Test list for SPQueryUtil querystring", SPListTemplateType.GenericList);
web.Update();
TestList = web.Lists[listId];
TestList.Fields.Add("TextCol", SPFieldType.Text, false);
TestList.Fields.Add("MultiTextCol", SPFieldType.Note, false);
TestList.Fields.Add("NumberCol", SPFieldType.Number, false);
TestList.Fields.Add("DateTimeCol", SPFieldType.DateTime, false);
TestList.Fields.Add("BoolCol", SPFieldType.Boolean, false);
TestList.Fields.Add("ChoiceCol", SPFieldType.Choice, false);
TestList.Fields.Add("MultiChoiceCol", SPFieldType.MultiChoice, false);
TestList.Fields.Add("GuidCol", SPFieldType.Guid, false);
TestList.Fields.Add("UrlCol", SPFieldType.URL, false);
TestList.Fields.Add("UserCol", SPFieldType.User, false);
TestList.Update();
SPListItem textItem = TestList.AddItem();
textItem["TextCol"] = "text1";
textItem.Update();
SPListItem textItemMulti = TestList.AddItem();
textItemMulti["MultiTextCol"] = "Multi text";
textItemMulti.Update();
SPListItem numberItem = TestList.AddItem();
numberItem["NumberCol"] = 100;
numberItem.Update();
SPListItem dateTimeCol = TestList.AddItem();
dateTimeCol["DateTimeCol"] = new DateTime(2000, 1, 1, 5, 10, 59);
dateTimeCol.Update();
SPListItem boolItem = TestList.AddItem();
boolItem["BoolCol"] = true;
boolItem.Update();
SPListItem choiceItem = TestList.AddItem();
choiceItem["ChoiceCol"] = "choice1";
choiceItem.Update();
var choicevalues = new SPFieldMultiChoiceValue();
choicevalues.Add("Green");
choicevalues.Add("Blue");
SPListItem chioceItemMulti = TestList.AddItem();
chioceItemMulti["MultiChoiceCol"] = choicevalues;
chioceItemMulti.Update();
SPListItem guidItem = TestList.AddItem();
guidItem["GuidCol"] = new Guid("96D74029-8482-4C52-8C4F-4A4040A77BC5");
guidItem.Update();
SPListItem urlItem = TestList.AddItem();
urlItem["UrlCol"] = "http://www.google.com";
urlItem.Update();
//SPListItem userItem = TestList.AddItem();
//textItemMulti["UserCol"] = "";
//userItem.Update();
}
}
using (SPWeb web = site.OpenWeb(this.webUrl))
{
TestList = web.Lists[this.listName];
}
}
}