문제

How is it possible to download file from document library by the help of item ID? In my data I have only item ID of a file which was uploaded to document library now I want to download the file i.e somehow get ServerRelativeUrl of the file uploaded,how is it possible in pnp js?

도움이 되었습니까?

해결책

You should get it by looking for the EncodedAbsUrl

var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Shared Documents')/items?$select=EncodedAbsUrl&$filter=Id eq 123";        

var requestHeaders = {
    "accept": "application/json;odata=verbose"}

$.ajax({
url: requestUri,
type: 'GET',
dataType: 'json',
headers: requestHeaders,
success: function (data) 
{        
   $.each(data.d.results, function(i,result) {
        var path = result.EncodedAbsUrl;
     });

  },
  error: function ajaxError(response) {
    alert(response.status + ' ' + response.statusText);
  }
});

Set your ID variable for the 123 in first line. Be sure to change the title of your document library in the first line as well. The variable "path" will hold your full file path for downloading. You just need to download it then.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top