locked
How to upload a document with values related to document properties in to document set at same time using Javascript object model RRS feed

  • Question

  • Hi,

          Problem Description: Need to upload a document with values related to document properties using custom form in to document set using JavaScript Object Model.

        Kindly let me know any solutions.

    Thanks


    Razvi444



    • Edited by Razvi444 Thursday, December 4, 2014 5:55 PM
    Tuesday, December 2, 2014 4:27 AM

Answers

All replies

  • There are 2 possibilities :

    1) Rest API - this will not work as it does not support Taxonomy fiels

    2) CSOM,

    Here you must have the ID, Guid and term label. Like:  You then must apppend these together for the value to set the field with. You must also set an additional field named like "NameOfFieldTaxHTField0". Example,

    string termValue = "3" + ";#" + "Accounting" + "|" + "9a071ed7-86f3-4874-ac6b-972ea93c8df5";
    
    uploadFile.ListItemAllFields["Type"] = termValue;
    
    uploadFile.ListItemAllFields["TypeTaxHTField0"] = termValue;

    If you don't have all the three values, then you will need to do a async call to the Metadata service and get the 3 values and form the string

    you can check this link too :https://social.msdn.microsoft.com/Forums/office/en-US/ecdbc803-db82-438a-b8bc-15656938e75e/add-document-with-managed-metadata-column-type?forum=sharepointdevelopmentprevious

    http://www.shillier.com/archive/2013/03/26/uploading-files-in-sharepoint-2013-using-csom-and-rest.aspx


    get2pallav
    Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

    Tuesday, December 2, 2014 6:30 AM
  • In case of SharePoint 2010 / 2013 on-premises you can use the Auto Tagger to bulk-tag your library (e.g. after migration) or activate real-time tagging (during document upload or item change) to apply appropiate managed metadata. Document content is exposed and considered via IFilters. You can simply use term labels and synonyms to fit the content or optionally apply more complex content classification rules (managed directly in term store).

    More Information: http://www.layer2solutions.com/en/products/Pages/SharePoint-Auto-Tagger-Installation-Setup.aspx

    Hope that helps.

    Thanks, Frank

    Tuesday, December 2, 2014 3:41 PM
  • The following code shows how to use REST/Ajax to upload a document to a document set.

    function uploadToDocumentSet(filename, content) {
        appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
        hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
        var restSource = appweburl +
            "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('/restdocuments/testds')/files/add(url='" + filename + "',overwrite=true)?@target='" + hostweburl + "'";
        var dfd = $.Deferred();
        $.ajax(
           {
               'url': restSource,
               'method': 'POST',
               'data': content,
               processData: false,
               timeout:1000000,
               'headers': {
                   'accept': 'application/json;odata=verbose',
                   'X-RequestDigest': $('#__REQUESTDIGEST').val(),
                   "content-length": content.byteLength
               },
               'success': function (data) {
                   var d = data;
                   dfd.resolve(d);
               },
               'error': function (err,textStatus,errorThrown) {
                   dfd.reject(err);
               }
           }
          );
        
        return dfd;
    
    }

    Then when this code returns you can use the following to update the metadata of the new document.

    function updateMetadataNoVersion(fileUrl) {
        appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
        hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
        var restSource = appweburl +
            "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('/restdocuments/testds')/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem?@target='" + hostweburl + "'";
    
        var dfd = $.Deferred();
    
        $.ajax(
        {
            'url': restSource,
            'method': 'POST',
            'data': JSON.stringify({
                'formValues': [
                    {
                    '__metadata': { 'type': 'SP.ListItemFormUpdateValue' },
                    'FieldName': 'Title',
                    'FieldValue': 'My Title2'
                }
                ],
                'bNewDocumentUpdate': true,
                'checkInComment': ''
            }),
            'headers': {
                'accept': 'application/json;odata=verbose',
                'content-type': 'application/json;odata=verbose',
                'X-RequestDigest': $('#__REQUESTDIGEST').val()
            },
            'success': function (data) {
                var d = data;
                dfd.resolve(d);
            },
            'error': function (err) {
                dfd.reject(err);
            }
        }
       );
    
        
    
        return dfd;
    }


    Blog | SharePoint Field Notes Dev Tools | SPFastDeploy | SPRemoteAPIExplorer

    Wednesday, December 3, 2014 3:25 AM
  • Hi,

       Thanks for posting solution, but actually need to upload a document with values related to document properties which are visible in the document content type, kindly propose any solution in case on document properties.

    Thanks


    Razvi444

    Wednesday, December 3, 2014 2:44 PM
  • Hi,

       Thanks for posting solution, but actually need to upload a document with values related to document properties which are visible in the document content type, is there any solution to upload document using JavaScript Library or kindly propose any solution in case on document properties related to content type.

    Thanks


    Razvi444

    Wednesday, December 3, 2014 2:48 PM
  • Hi,

      Thanks for posting your answer, Kindly propose any solution using JavaScript Library.

    Thanks

     


    Razvi444

    Wednesday, December 3, 2014 2:51 PM
  • HI Razvi,

    I am sending you the link which can help u to resolve the prob

    its is basicly the javaacript lib which can help you

    http://geekswithblogs.net/ThorvaldBoe/archive/2014/06/06/how-to-upload-files-to-a-sharepoint-2013-document-library.aspx

    http://apigee.com/docs/api-services/reference/javascript-object-model

    Please mark the Answer and vote if you think that above solution can help you to resolve the prob

    • Marked as answer by Lindali Friday, December 19, 2014 9:41 AM
    Wednesday, December 3, 2014 5:15 PM