Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

Unable to select the items in multiselect through code

Answered
New post

Comments

2 comments

  • Official comment
    Alex Novotny

    Hi Vijay, 

    Thank you for bringing this up! I have an answer for you. You will want to create a string array with the options you want. 



    Hope this helps! 

    Thanks, 

    Alex, Box Developer Advocate

    private static async Task CreateMetadataTemplateInstance(BoxClient adminClient)
    {
    string[] selectedOptions = { "Author1", "Author2"};
    var metadataValues = new Dictionary<string, object>()
    {
    { "author", selectedOptions }
    };

    var metadata = await adminClient.MetadataManager.SetFileMetadataAsync(fileId: "123456", metadataValues, "enterprise", "multiselecttest");

    Console.WriteLine("Instance Added To File: ", metadata.ToString());

    }
    Comment actions Permalink
  • Vijay Krishnan1

    I tried with the below also and getting the same error.

    List<string> lstSelectedAuthors = new List<string>() { "Author2", "Author3" };
    var metadataValues = new Dictionary<string, object>();

    metadataValues.Add("author", JsonConvert.SerializeObject(lstSelectedAuthors));

    var metadata = await _boxClient.MetadataManager.SetFileMetadataAsync(123456, metadataValues, "enterprise", "multiselecttest");

    0
    Comment actions Permalink

Please sign in to leave a comment.