【问题标题】:How to programmatically add a hashtag to a List item in Sharepoint 2013?如何以编程方式将主题标签添加到 Sharepoint 2013 中的列表项?
【发布时间】:2013-03-19 11:23:10
【问题描述】:
【问题讨论】:
标签:
sharepoint
sharepoint-api
sharepoint-2013
【解决方案1】:
我昨天确实偶然发现了这个,现在无法访问 devbox,但您应该开始在 Microsoft.SharePoint.Client.Social 中查找
即
context.Load(context.Web);
SocialFeedManager socialFeedManager = new SocialFeedManager(context);
如果你不打败我,我会在 devbox 再次上线时提供更多信息! :)
【解决方案2】:
我终于找到了路:
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。