如何更新文档库中的多个项目 [英] How to update multiple items in documents library
问题描述
我有一个文档库&外部列表.
I have a Document Library & External List.
首先,我想从外部列表"中读取数据列(名称,C1,C2,C3)
first i want to read the data from External list columns (Name,C1,C2,C3)
列(名称)将为查找
在文档库中我想更新列
C1,C2,C3
列(名称)将为查找
在文档库中,我想更新所有项目的元数据.
In Document Library i want to update Metadata for all items.
我该如何实现?
sal
推荐答案
对于名称"字段,这是一个查找字段,将从外部列表中获取数据.
For the Name field, it's a lookup field which will get data from External List.
SharePoint会将此字段转换为外部数据"输入字段,此字段将具有以下定义:
SharePoint will Convert this field to "External Data" Type field, this field will have below definition:
<Field Type="BusinessData" DisplayName="lookup" Required="FALSE" EnforceUniqueValues="FALSE" ID="{e59deefd-aba5-4adc-bd33-dea08a324cb3}" SourceID="{cfc3bcc8-597f-4fb0-ba9e-c59aa7f59c4d}" StaticName="lookup" BaseRenderingType="Text" Name="lookup" ColName="nvarchar10" RowOrdinal="0" Version="5" Group="" SystemInstance="Employee" EntityNamespace="http://sp/sites/dev" EntityName="New external content type" BdcField="Name" Profile="" HasActions="True" SecondaryFieldBdcNames="3%205%20Id%20Name%204" RelatedField="New_x0020_external_x0020_content_x0020_type_ID"
我们需要为此字段更新DisplayName和RelatedField属性以设置值,如下所示:
We need to update the DisplayName and RelatedField property for this field to set value like below:
item["lookup"] = "Jerry";
item["New_x0020_external_x0020_content_x0020_type_ID"] =Microsoft.SharePoint.BusinessData.Infrastructure.EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { "Jerry" });
更多信息:
对于外部列表中的其他文本字段,我们可以像下面这样设置它,完成代码:
For other text field in external list, we can set it like below, completed code:
static void Main(string[] args)
{
var client = new Microsoft.SharePoint.Client.ClientContext("http://sp/");
var externallist = client.Web.Lists.GetByTitle("dd");
CamlQuery query=new CamlQuery();
ListItemCollection items = externallist.GetItems(query);
client.Load(items);
client.ExecuteQuery();
ListItem item = items[0];
string c1 = item["c1"].ToString();
string c2 = item["c2"].ToString();
string c3 = item["c3"].ToString();
var name = item["Name"].ToString();
updatecolumn(c1, c2, c3,name);
}
private static void updatecolumn(string c1, string c2, string c3, string name)
{
var client = new Microsoft.SharePoint.Client.ClientContext("http://sp/");
var library = client.Web.Lists.GetByTitle("Myform");
CamlQuery query = new CamlQuery();
ListItemCollection items = library.GetItems(query);
client.Load(items);
client.ExecuteQuery();
foreach (ListItem item in items)
{
item["c1"]=c1;
item["c2"] = c2;
item["c3"] = c3;
item["lookup"] =name;
item["New_x0020_external_x0020_content_x0020_type_ID"] = Microsoft.SharePoint.BusinessData.Infrastructure.EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { name });
item.Update();
client.ExecuteQuery();
}
}
谢谢
最好的问候
这篇关于如何更新文档库中的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!