What is the easy way to update Managed Metadata field multi select values using client object model C#?

The below mentioned code works sometimes and doesn't most of the time. What is the real best way to update multi select managed metadata fields?
Microsoft.SharePoint.Client.File file = site.GetFileByServerRelativeUrl("/sites/myspsite/Documents/Presentation2.pptx");
clientContext.Load(file);
clientContext.ExecuteQuery();
ListItem currentItem = file.ListItemAllFields;
clientContext.Load(currentItem);
clientContext.ExecuteQuery();
currentItem["Country"] = "-1;#India|1d13cfe9-d6f4-4bd3-a6c7-4b46a81f2a96;#-1;#China|9c1dff73-82db-44b1-8d70-f4258dd24e47;#-1;#USA|b9295c0b-67d4-4dc5-99d4-e88af888de48";
currentItem["Title"] = "Demo Doc";
currentItem.Update();
clientContext.ExecuteQuery();
file.CheckIn("test check-in", CheckinType.MajorCheckIn);
clientContext.ExecuteQuery();
Anuradha!!

Hi,
Here are two blog for your reference:
How to Work with Managed Metadata Columns by Using the SharePoint Client Object Model
http://blogs.msdn.com/b/sharepointdev/archive/2011/11/18/how-to-work-with-managed-metadata-columns-by-using-the-sharepoint-client-object-model-kaushalendra-kumar.aspx
SharePoint 2010 Code Tips – Setting a Managed Metadata Field with the Client Object Model
http://sharepointfieldnotes.blogspot.com/2011/08/sharepoint-2010-code-tips-setting.html
Best Regards
Dennis Guo
TechNet Community Support

Similar Messages

  • What's the proper way to update this table field?

    I've got a table with a field of TOTAL.  There's a linked table with a field of AMOUNT.  There's one main table record to multiple linked records.   I'd like to replace the TOTAL with the sum of Amount for each link.   I'm
    having a hard time setting up an update query to do that.  Any suggestions?
    ajw

    The proper way is almost certainly not to store the totals in a column in a table at all, but to compute them in an aggregating query, e.g. to return the sum of transaction amounts per customer:
    SELECT CustomerID, SUM(Amount) AS TotalAmount
    FROM Transactions
    GROUP BY CustomerID;
    Storing aggregated values is only necessary if these can legitimately be amended independently of the values from which they are computed.  This is not out of the question, but is rarely the case.
    Ken Sheridan, Stafford, England

  • What is the easier way to turn voice controller off?

    what is the easier way to turn voice controller off?

    you can turn of the voice dial but as far as i know you can not turn off the voice controller
    if you want to turn of the voice dial just go to setting then to general after that to passcode and turn off the voice dial option

  • What's the best way to update my Mac with the latest version of Adobe Flash Player?

    I've been getting prompts whenever I look at certain websites to download the latest version of Adobe Flash Player.  I'm skeptical as to responding to those prompts.  What is the best way to update my Mac Pro with the latest version of Adobe Flash Player?

    You might also want to consider uninstalling Adobe Flash... I currently don't have it installed and haven't needed to install it.  Most websites are now coded in HTML 5 so that the iOS devices can actually visit them.  I can still watch YouTube videos et al.  About the only thing I can't do is play Flash games... but they're a resource hog anyways. 
    Try going without for a day or two and see just how many sites you visit no longer require it.  A lot of people keep it installed out of habit, not out of necessity.  If you have Flash installed, visit a site and it's out of date, it will tell you to update your Flash.  What it won't do is tell you is that had Flash not been installed, it would have used the HTML 5 code instead.  Think about it... if an iOS device can't run Flash at all... it can't visit this site if it were written only to use Flash.  What site would eliminate such a huge portion of their market base?  You'd be surprised at how many sites use HTML 5.  Uninstall Flash and see for yourself.

  • What is the best way to update an ALV tree?

    Hello all of you
    What is the best way to update an ALV tree?
    In my case, by double clicking on a branch, a table is updated and an icon should be updated in the alv tree.
    I use the class CL_SALV_TREE
    Thanks for your help

    Call method REFRESH!

  • I have an iPhone 4 with iOS 5.1. What is the best way to update my phone to the latest iOS platform?

    I have an iPhone 4 with iOS 5.1. What is the best way to update my phone to the latest iOS platform?

    you can update over the air with strong wireless signal, or by connecting to a computer running iTunes.  Either works well.  If you do the update over the air, be sure and attach your iPhone to a wall outlet so you have a solid power supply and don't risk the battery dying during the update.
    The iTunes approach installs a much larger file because of the connection, but if you have not updated since 5.1 that might be a better approach...replace the entire operating system instead of patching. 
    Either way, backup the iPhone yourself just for your own protection in the off-chance something should go wrong...a little paranoia while updating is a good thing

  • What is the best way to update the delivery time?

    Hi All,
    One of the tasks I have in my job is to updste purchase orders with information found in the orderconfirmation we receive. In the order screen, ME22N, you can change the date in the item, where you have all positions listed. But you can also change it in the tab classifications.
    What is the best way to update the delivery time?
    Best Regards
    Praveen

    Hi
    It may userfull to you
    If you change the delivery date after you have send the PO, then the statistical delivery date is still containing the old delivery date., as long the order is not send this date is changed together with the delivery date.
    Vendor evaluation is performed based on statistical delivery date.
    So if you are responsible for a date change, then you change both dates, that the vendor does not get bad points. but if the vendor cannot deliver at the wished dates, then you change the delivery date only, that all people in your company and MRP run can rely on the new delivery date, but your vendor is evaluated against the old date, because of his fault.
    regards
    Madhu

  • What is the best way to update iPad 2

    What is the best way to update iPad 2

    If you are still using IOS 4
    Connect your iPad to iTune (computer) and Check for Updates. Backup before you proceed with update.
    http://i1224.photobucket.com/albums/ee374/Diavonex/Album%208/d549b56e8567252791a 1834379e59068.jpg

  • What's the easiest way to update my site regularly?

    What's the easiest way to update my site? I update with new content every month, sometimes more often. (I don't use .mac) When I do, I delete my whole site, then have to upload the whole site with it's updates (the main file along with the index file).
    Is there a way to only update, let's say, ONE page? And if so, will I still have to delete that page?
    Thanks!
    http://faithmountainaz.com/FaithMountain/Home.html

    Hi,
    I wrote my personal experience in that thread:
    http://discussions.apple.com/thread.jspa?messageID=5431205&tstart=0#5431205
    I think you will find all you need
    If not, just ask...
    Enjoy your day,
    Cédric

  • What is the best way to clone a form field in BC

    Hi,
    What is the best way to clone a form field in BC.  I tried using jquery .clone.  It works fine on other forms for me but not on the BC forms, why? is it just me?  Any help would be great. Thanks

    I mean, duplicate a field with the click of a button.
    I think this should work, but it's not and  I am linked to the jquery library in the head of my page.
    <script type="text/javascript">
    $(document).ready(
      function() {
        $('input#tmpAddRow').click(
          function($e) {
            $e.preventDefault();
            $('tr#tmp').clone(true).removeAttr('id').appendTo('tbody');
        $('tr input[type=text]').focus(
          function() {
            $(this).addClass('myFocused');  
        ).blur(
          function() {
            $(this).removeClass('myFocused');
        </script>
    <img alt="" style="border: 0px solid; width: 200px; height: 134px; float: left;" src="/images/pv logo 3d.png" />
    <h3 style="text-align: center; color: #0000ff; text-shadow: #999999 0px 1px 5px;">Member Directory Listing</h3>
    <p style="text-align: center;">If you would like to be listed in the Pine Valley Middle School Directory, please fill out this form.  Only fill out the areas you would like to show up in our Directory.</p>
    <div style="margin-left: 130px;" class="form_bg">
    <form action="/CustomContentProcess.aspx?CCID=5656&amp;OID={module_oid}&amp;OTYPE={module_otype }" method="post" enctype="multipart/form-data" onsubmit="return checkWholeForm45842(this)" name="catcustomcontentform45842">
        <table cellspacing="0" cellpadding="2" border="0" class="webform">
            <tbody>
                <tr>
                    <td id="tmp"><label for="ItemName">First Name</label><br />
                    <input type="text" value="{module_firstname}" maxlength="255" id="ItemName" name="ItemName" class="cat_textbox_small" /><br />
                    <input type="button" id="tmpAddRow" value="Add a Row" />
                    </td>
                </tr>
                <tr>
                    <td><label for="CAT_Custom_131512">Last Name</label><br />
                    <input type="text" value="{module_lastname}" class="cat_textbox" id="CAT_Custom_131512" name="CAT_Custom_131512" maxlength="1024" /></td>
                </tr>
                <tr>
                    <td><label for="CAT_Custom_131509">Number</label><br />
                    <input type="text" value="{module_homephone}" class="cat_textbox" id="CAT_Custom_131509" name="CAT_Custom_131509" maxlength="1024" />
                    </td>
                </tr>
                <tr>
                    <td><label for="CAT_Custom_131510">Email</label><br />
                    <input type="text" value="{module_emailaddress}" class="cat_textbox" id="CAT_Custom_131510" name="CAT_Custom_131510" maxlength="1024" /></td>
                </tr>
                <tr>
                    <td><label for="ItemAddress">Address</label><br />
                    <input type="text" value="{module_homeaddress}" maxlength="500" class="cat_textbox" id="ItemAddress" name="ItemAddress" />
                    </td>
                </tr>
                <tr>
                    <td><label for="ItemCity">City</label><br />
                    <input type="text" value="{module_homecity}" maxlength="255" class="cat_textbox" id="ItemCity" name="ItemCity" /></td>
                </tr>
                <tr>
                    <td><label for="ItemState">State</label><br />
                    <input type="text" value="{module_homestate}" maxlength="255" class="cat_textbox" id="ItemState" name="ItemState" />
                    </td>
                </tr>
                <tr>
                    <td><label for="ItemZip">Zipcode/Postcode</label><br />
                    <input type="text" value="{module_homezip}" maxlength="255" class="cat_textbox" id="ItemZip" name="ItemZip" /></td>
                </tr>
                <tr>
                    <td class="hidden"><label for="FirstName">First Name</label><br />
                    <input type="text" value="{module_firstname}" class="cat_textbox" id="FirstName" name="CAT_Custom_131511" maxlength="1024" /></td>
                </tr>
                <tr>
                    <td><input type="submit" id="catcustomcontentbutton" value="Submit" class="cat_button" /></td>
                </tr>
            </tbody>
        </table>
        <script type="text/javascript" src="/CatalystScripts/ValidationFunctions.js"></script>
        <script type="text/javascript" src="/CatalystScripts/Java_DatePicker.js"></script>
        <script type="text/javascript">
    //<![CDATA[
    var submitcount45842 = 0;function checkWholeForm45842(theForm){var why = "";if (theForm.ItemName) why += isEmpty(theForm.ItemName.value, "Item Name");if (theForm.Days) why += isNumericIfVisible(theForm.Days, "days"); if (why != ""){alert(why);return false;}if(submitcount45842 == 0){submitcount45842++;theForm.submit();return false;}else{alert("Form submission is in progress.");return false;}}
    //]]>
    </script>
        <script type="text/javascript">
        jQuery("#ItemName").blur(function(){
            jQuery("#FirstName").val(jQuery("#ItemName").val());
    </script>
    </form>
    </div>

  • Hello, what is the best way for me to convert RW2 raw format for use in Photoshop CC

    Hello, what is the best way for me to convert RW2 raw format for use in Photoshop CC. I would appreciate any help with this.

    Thanks for the quick help. I do have to leave for work. When I try to
    download the images from the camera they seem to only be in jpeg (I don't
    see any rw2 or raw files to download). If I select the jpeg file it seems
    to only download a jpeg file. I do understand that I do have the option to
    open the jpeg in RAW. In doing this, is all the extra information included
    in the RAW file there or is it lost coming from the camera
    Once again thank you for trying to make me understand how this works.
    Have a great day.
    On Sat, Sep 13, 2014 at 12:14 PM, ssprengel <[email protected]>

  • Update Managed Metadata field in SharePoint 2013 Designer Workflow for O365

    Hi Guys,
    I need to update the managed metadata field in SharePoint Custom List using Workflow but its not working. I have also tried to use the HTTP WebService POST Operation but no luck.
    Am doing this for a SharePoint Online (O365) Site.
    Has anyone worked on something similar and was able to get it running ?
    I saw a post to create a custom Workflow Activity but I don't have a choice to go with the custom code option.
    http://patrickboom.wordpress.com/2013/07/23/workflow-activity-set-managed-metadata-column/
    I was able to achieve this by creating a SP 2010 based Workflow for O365. Which means that it worked well with SP 2010.
    Is there a different way to do it in 2013 ? I tried almost all options apart from creating custom Activity but nothing worked out. 
    Any help would be great.
    Thanks,
    Nutan
    Nutan Sharma

    Hi Nutan,
    According to your description, my understanding is that you want to update Managed Metadata field with SharePoint 2013 Designer for SharePoint Online.
    As far as I know, there is not an OOB action to achieve your requirement with SharePoint 2013 Designer for SharePoint 2013. Customizing a workflow action is a better option to achieve it.  Why didn’t you customize a workflow action as Patrick’s blog?
    In addition, please take a look at the article about Nintex workflow, check whether it is useful for you:
    http://habaneroconsulting.com/insights/setting-managed-metadata-fields-in-a-nintex-workflow#.UykBSf6KDHo
    As this issue is about SharePoint Online, I suggest you create a new thread on SharePoint Online forum:
    http://social.technet.microsoft.com/Forums/en-US/home?forum=onlineservicessharepoint . More experts will assist you.
    I hope this helps.
    Thanks,
    Wendy
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Wendy Li
    TechNet Community Support

  • Quering the database using Client Object Model

    Hi,
    I have to fetch the list items from a list named "Project Status" and display it in a table using
    Client Object model.
    The equivalent server side code is:
    SPWeb web = SPContext.Current.Web;
    SPList list = web.Lists["Project Status"];
    DataTable dt1 = new DataTable();
    try
    if (list.ItemCount > 0)
    DataColumn dc;
    DataColumn dc1;
    dc = new DataColumn("ProjectId", Type.GetType("System.String"));
    dc1 = new DataColumn("Project Name", Type.GetType("System.String"));
    dt1.Columns.Add(dc);
    dt1.Columns.Add(dc1);
    DataRow dr;
    foreach (SPListItem item in list.Items)
    dr = dt1.NewRow();
    dr["ProjectId"] = item["ProjectId"];
    dr["Project Name"] = item["Project Name"];
    dt1.Rows.Add(dr);
    Repeater1.DataSource = dt1;
    Repeater1.DataBind();
    catch (Exception Ex)
    throw Ex;
    1 more issue what i face is providing two links in the Visual WebPart and their navigate url is based on a condition that is fetched from the database. This corresponding code has to be converted to
    Client Object Model.
    string user = web.CurrentUser.LoginName;
    string userID = user.Split(new char[] { '\\' })[1];
    string connString = @"Data Source=NorthWind;Initial Catalog=EmployeeDB;User ID=sa;Password=Newuser123";
    string query = "select * from EMPLOYEE_PROFILE";
    SqlConnection conn = new SqlConnection(connString);
    SqlCommand cmd = new SqlCommand(query, conn);
    try
    conn.Open();
    DataTable t1 = new DataTable();
    using (SqlDataAdapter a = new SqlDataAdapter(cmd))
    a.Fill(t1);
    DataRow[] dr = t1.Select("PsNo = '" + userID + "'"); //This will select all rows where the Name Column has current user
    foreach (DataRow r in dr)
    string bU = r["DeputedBU"].ToString();
    if (bU == "INS" || bU == "BFS")
    lnkPM.NavigateUrl = web.Site.WebApplication.Sites[0].Url + "/Dashboard.aspx";
    lnkSummary.NavigateUrl = web.Site.WebApplication.Sites[0].Url + "/DashboardWithHyperlinks.aspx";
    else
    lnkPM.Visible = false;
    lnkSummary.Visible = false;
    catch (Exception)
    throw;
    finally
    conn.Close();
    Any help would be appreciated.

    Hi,
    According to your post, there would be two questions in this single thread.
    It is recommended to post one question in one single thread which will make others easier to focus on one question in one thread.
    For the first question, you want to fetch list items and put into a DataTable object using Client Object Model.
    To fetch list items from a list using Client Object Model, you can take a look at the code snippet below from MSDN:
    http://msdn.microsoft.com/en-us/library/office/ee534956(v=office.14).aspx
    For the second question, you might need to retrieve the User object and site collections object using Client Object Model.
    However, if you can develop a Visual Web Part for your site, it means that you will be able to access the SharePoint Object Model which has more powerful APIs, so there is no
    need to use Client Object Model in a Visual Web Part.
    Best regards
    Patrick Liang
    TechNet Community Support

  • Unable to get the SharePoint 2013 List names using Client object model for the input URL

    Please can you help with this issue.
    We are not able to get the SharePoint 2013 List names using Client object model for the input URL.
    What we need is to use default credentials to authenticate user to get only those list which he has access to.
    clientContext.Credentials = Net.CredentialCache.DefaultCredentials
    But in this case we are getting error saying ‘The remote server returned an error: (401) Unauthorized.’
    Instead of passing Default Credentials, if we pass the User credentials using:
    clientContext.Credentials = New Net.NetworkCredential("Administrator", "password", "contoso")
    It authenticates the user and works fine. Since we are developing a web part, it would not be possible to pass the user credentials. Also, the sample source code works perfectly fine on the SharePoint 2010 environment. We need to get the same functionality
    working for SharePoint 2013.
    We are also facing the same issue while authenticating PSI(Project Server Interface) Web services for Project Server 2013.
    Can you please let us know how we can overcome the above issue? Please let us know if you need any further information from our end on the same.
    Sample code is here: http://www.projectsolution.com/Data/Support/MS/SharePointTestApplication.zip
    Regards, PJ Mistry (Email: [email protected] | Web: http://www.projectsolution.co.uk | Blog: EPMGuy.com)

    Hi Mistry,
    I sure that CSOM will authenticate without passing the
    "clientContext.Credentials = Net.CredentialCache.DefaultCredentials" by default. It will take the current login user credentials by default. For more details about the CSOM operations refer the below link.
    http://msdn.microsoft.com/en-us/library/office/fp179912.aspx
    -- Vadivelu B Life with SharePoint

  • Setting the default value to taxonomy column in sharepoint 2010 using client object model

    I am creating a metadata column and I want to set its default value in sharepoint 2010 using client object model. Can anyone help me?
    My code for creating metadata column is as below:
                ClientContext clientContext = new ClientContext(siteUrl);
                Web site = clientContext.Web;
                List list = site.Lists.GetByTitle("LibraryName");
                FieldCollection collField = list.Fields;
                string fieldSchema = "<Field Type='TaxonomyFieldType' DisplayName='SoftwareColumn' Name='SoftwareColumn' />";
                collField.AddFieldAsXml(fieldSchema, true, AddFieldOptions.DefaultValue);
                //oneField.DefaultValue = "ASP.NET|4c984b91-b308-4884-b1f1-aee5d7ed58b2"; // wssId[0].ToString() + ";#" + term.Name + "|" + term.Id.ToString().ToLower();
                clientContext.Load(collField);           
                clientContext.ExecuteQuery();

    Hi,
    Please try the code like this:
    ClientContext clientContext = new ClientContext("http://yoursite/");
    List list = clientContext.Web.Lists.GetByTitle("List1_mmsfield");
    clientContext.Load(list);
    clientContext.ExecuteQuery();
    FieldCollection fields = list.Fields;
    clientContext.Load(fields);
    clientContext.ExecuteQuery();
    Field f = fields.GetByTitle("mms");
    clientContext.Load(f);
    clientContext.ExecuteQuery();
    Console.WriteLine(f.Title + "---" + f.DefaultValue);
    //2;#A2|a0a95267-b758-4e4d-8c39-067069fd2eef
    //1;#A1|641f5726-992c-41c8-9ddc-204a60b88584
    f.DefaultValue = "1;#A1|641f5726-992c-41c8-9ddc-204a60b88584";
    f.Update();
    clientContext.Load(f);
    clientContext.ExecuteQuery();
    Console.WriteLine(f.Title + "---" + f.DefaultValue);
    Best regards
    Patrick Liang
    TechNet Community Support

Maybe you are looking for

  • How can I Download and use ibooks?

    Hi All, I have iMac 10.6.8 Snow Leopard iMac. I want to create and upload a book to ipad using iBook but I need 10.7 or higher. I have read some of the Forum answers but I am still a bit confused. If I install Mavericks will that be happy on my iMac

  • Poor Customer service unauth charges iTunes over Paypal

    I just thought I would share this exchange with the community. Do yourself a favor and remove your billing method from iTunes. You can expect this treatment when it occurs. Not only does it say that iTunes takes no responsibility for your account bei

  • Audition 3.0 Crashing w/BSOD msgs.

    I don't know if this issue is due to my new install of Audition 3.0 that I just bought, but I'm not getting these errors when I'm running Sonar, and ONLY when I'm running Au3.0. Any advice you can give me on a possible remedy would be welcome. I had

  • Erasing Duplicate files from folders... not from iTunes....

    I want to know if I can locate (using a program or just my Mac) all the files that I have deleted in the past from iTunes but for some reason are still on my hard drive. It is a pain! And when I edit the name, artist, and genre on iTunes they do not

  • How to report on machines that are missing an application?

    It seems to be a difficult task to report on PCs that are missing a specific exe or application. For example I ran a report and found 418 of 510 machines have the exe I am looking for. I manually merged the information on a page or 2 by printing both