Question

I would like to add specific hashtags to List items on a Sharepoint 2013 App using the C# components. I want to mimic the "Tags and Note Board" feature.

I found how to add a tag on the server here http://msdn.microsoft.com/en-us/library/ff770863.aspx, but as I am using Sharepoint Online I need to use the Client API.

Was it helpful?

Solution 2

I have finally found the way:

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();

If you find a better solution, please post it, this one works pretty well.

If you want to know how to format the "Term Label|term-unique-id", look at the Taxonomy Term Store, under the Sharepoint Admin page. A term's unique id sample: d5e733d2-a904-4bee-afbd-632440fdc125.

OTHER TIPS

I did stumble on this yesterday, can't reach the devbox right now but you should start looking in Microsoft.SharePoint.Client.Social

I.e.

context.Load(context.Web);
SocialFeedManager socialFeedManager = new SocialFeedManager(context);

I'll return with more info when the devbox is online once again if you don't beat me to it! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top