1

I need to get document ID of newly uploaded document using JQuery, any help highly be appreciated.

I'm trying below code which is not working and gives 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);
}
  • What is the value of docTitle that you are passing? Also, why not use GetFileByServerRelativeUrl('/Folder Name/file name') – Akhoy Aug 28 '15 at 16:29
  • doctitle is the value of uploaded file. I still can't able to retrieve docid for uploaded document. – MAK Aug 31 '15 at 6:01
0

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));
    },
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.