Get uploaded document id using JQuery

I'm trying to retrieving document ID of newly uploaded document using JQuery, any help highly be appreciated.

I'm trying below code which is not working error, 404 not found;

function getListData() {

    var docTitle = jQuery('#fileButton').val();
var fileCollectionEndpoint = String.format(
            "{0}/_api/web/lists/getByTitle('Private%20Documents')/RootFolder/Files/Get(url='{1}', overwrite=true)",
            _spPageContextInfo.webAbsoluteUrl, docTitle);
    
    $.ajax({
        url: fileCollectionEndpoint,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
        },
        success: Succeeded,
        error: function Failed() {
        alert('Error!');
    }

    });
}

function Succeeded(data) {

   var listItemInfo = "";

   $.each(data.d.results, function (key, value) {
       listItemInfo += 'ID: ' + value.Id +
           ';';
   });

   alert(listItemInfo);
}


  • Edited by Asif Kazi Friday, August 28, 2015 3:06 PM
August 28th, 2015 3:03pm

I can't able to retrieve docid of uploaded document. But, i can able to retrieve docid for all documents.
Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 2:04am

Hi,

Do you want to get the document id in the EditForm.aspx page?

I suggest you provide more information about your requirement for further research.

Best Regards,

Dennis Guo

August 31st, 2015 7:59am

Hi,

Any update?

Best Regards,

Dennis

Free Windows Admin Tool Kit Click here and download it now
September 9th, 2015 10:44pm

Hi

The issue is resolved; for some reason loop was not working and I used the code below which worked.

                             

// Get the list item that corresponds to the file by calling the file's ListItemAllFields property.
    function getListItem(fileListItemUri) {

        // Send the request and return the response.
        return $.ajax({
            url: fileListItemUri,
            type: "GET",
            headers: { "accept": "application/json;odata=verbose" 
        },
        success: function(data) {
           var dataResults = data.d;

      var ID  = dataResults.ID;
      // alert(ID);

      var  dvelement1 = $("#fileButton1").val();
      var inputNode1 = dvelement1.replace("C:\\fakepath\\", "")

      $("#T8").append('<div id="del' + dataResults.ID +'"> <li  value="$dvelement" > &nbsp &nbsp'+inputNode1+' &nbsp &nbsp </li> </div> ');     
   },
            error: function(xhr, textStatus, errorThrown) {
            alert("error:"+JSON.stringify(xhr));
        },
        });
    }

Thanks

September 9th, 2015 11:04pm

Hi,

Thanks for sharing! It will help others who suck with the problem!

Best Regards,

Dennis

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 12:31am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics