如何在Sharepoint 2013中以编程方式向列表项添加标签?
我想使用C#组件为Sharepoint 2013应用程序上的项目列表添加特定的hashtag。 我想模仿“标签和记事本”功能如何在Sharepoint 2013中以编程方式向列表项添加标签?,sharepoint,sharepoint-api,sharepoint-2013,Sharepoint,Sharepoint Api,Sharepoint 2013,我想使用C#组件为Sharepoint 2013应用程序上的项目列表添加特定的hashtag。 我想模仿“标签和记事本”功能 我在这里找到了如何在服务器上添加标记,但由于我使用Sharepoint Online,我需要使用客户端API。我昨天偶然发现了这个问题,现在无法访问devbox,但您应该开始在Microsoft.Sharepoint.Client.Social中查找 即 当devbox再次联机时,如果您不抢先一步,我将返回更多信息!:) 我终于找到了方法: public void Asy
我在这里找到了如何在服务器上添加标记,但由于我使用Sharepoint Online,我需要使用客户端API。我昨天偶然发现了这个问题,现在无法访问devbox,但您应该开始在Microsoft.Sharepoint.Client.Social中查找 即
当devbox再次联机时,如果您不抢先一步,我将返回更多信息!:) 我终于找到了方法:
public void AsyncEvent(SPRemoteEventProperties properties) {
...
List lst = clientContext.Web.Lists.GetByTitle(properties.ItemEventProperties.ListTitle);
clientContext.Load(lst);
clientContext.ExecuteQuery();
ListItem item = lst.GetItemById(properties.ItemEventProperties.ListItemId);
clientContext.Load(item.ParentList, l => l.Fields.Where(field => field.Title == "FieldName"));
clientContext.ExecuteQuery();
foreach(TaxonomyField field in item.ParentList.Fields) {
TaxonomyFieldValueCollection newTopics = new TaxonomyFieldValueCollection(clientContext, String.Empty, field);
newTopics.PopulateFromLabelGuidPairs("Term A Label|term-a-unique-id;Term B Label|term-b-unique-id");
field.SetFieldValueByValueCollection(item, newTopics);
}
item.Update();
clientContext.ExecuteQuery();
如果你找到一个更好的解决方案,请张贴,这一个工作得很好
如果您想知道如何格式化“术语标签|术语唯一id”,请查看Sharepoint管理页面下的分类术语库。术语的唯一id示例:d5e733d2-a904-4bee-afbd-632440fdc125
public void AsyncEvent(SPRemoteEventProperties properties) {
...
List lst = clientContext.Web.Lists.GetByTitle(properties.ItemEventProperties.ListTitle);
clientContext.Load(lst);
clientContext.ExecuteQuery();
ListItem item = lst.GetItemById(properties.ItemEventProperties.ListItemId);
clientContext.Load(item.ParentList, l => l.Fields.Where(field => field.Title == "FieldName"));
clientContext.ExecuteQuery();
foreach(TaxonomyField field in item.ParentList.Fields) {
TaxonomyFieldValueCollection newTopics = new TaxonomyFieldValueCollection(clientContext, String.Empty, field);
newTopics.PopulateFromLabelGuidPairs("Term A Label|term-a-unique-id;Term B Label|term-b-unique-id");
field.SetFieldValueByValueCollection(item, newTopics);
}
item.Update();
clientContext.ExecuteQuery();