none
sharepoint c# update file that is opened in word RRS feed

  • Question

  • Hello,

    this is description of my problem:

    For example, I have one word document in a document library. When this document is opened in MS Word, I cannot update properties of that file from code (CSOM or JSOM or SSOM). What do I need to do so that I could update properties of the file when file is opened in Word??

    Thanks in advance

    Saturday, January 7, 2017 9:44 PM

All replies

  • Hi SPManiac,

    Here is a code snippet about updating document properties using CSOM:

    ClientContext clientContext = new ClientContext("http://sp");
     Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("Documents");
                clientContext.Load(spList);
                clientContext.ExecuteQuery();
    
                if (spList != null && spList.ItemCount > 0)
                {
                    Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml =
                       @"<View Scope='RecursiveAll'>  
                 <ViewFields><FieldRef Name='Title' /><FieldRef Name='choice' /></ViewFields> 
          </View>";
    
                    ListItemCollection listItems = spList.GetItems(camlQuery);
                    clientContext.Load(listItems);
                    clientContext.ExecuteQuery();
                    foreach (ListItem item in listItems)
                    {
                        item["Title"] = "test";
                        item.Update();
                        clientContext.Load(item);
                        clientContext.ExecuteQuery();
                    }
    
                }

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, January 9, 2017 3:14 AM