Document or list items can be easily fetched using REST calls, recently went into an while fetch the details from a document library using REST call, all documents are opening properly except the image files due to parameter issue. I am a small code snippet for fetching all type file URLs from a SharePoint Document library.

function GetDocumentsByTitle(docTitle) {
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle(docTitle)/Items?$select= Created,Author/FirstName,Author/LastName, FileLeafRef,FileRef/FileRef&$expand=Author/Id", 
    type: "GET", 
    headers: {"accept": "application/json;odata=verbose"}, 
    success: function (data) { 
        if (data.d.results) { 
            var listItems = " ";
        for (var i = 0; i < data.d.results.length; i++) {  
            listItems += "<div ><a target='_blank'  href='"+data.d.results[i].FileRef+"'>"+data.d.results[i].FileLeafRef+"</a><p>"+String.format("{0:d}",new Date(data.d.results[i].Created))+",&nbsp;"+data.d.results[i].Author.FirstName+"&nbsp;"+data.d.results[i].Author.LastName+"</p></div>";            

    error: function (errMsg) { 
        alert(errMsg.status + ': ' + errMsg.statusText); 

In above code snippet, output is shown a div with id divResults.

Adnan, a distinguished professional, boasts an impressive track record as a Microsoft MVP, having achieved this prestigious recognition for the eighth consecutive year since 2015. With an extensive career spanning over 18 years, Adnan has honed his expertise in various domains, notably excelling in SharePoint, Microsoft 365, Microsoft Teams, the .Net Platform, and Microsoft BI. Presently, he holds the esteemed position of Senior Microsoft Consultant at Olive + Goose. Notably, Adnan served as the MCT Regional Lead for the Pakistan Chapter from 2012 to 2017, showcasing his leadership and commitment to fostering growth within the tech community. His journey in the realm of SharePoint spans 14 years, during which he has undertaken diverse projects involving both intranet and internet solutions for both private and government sectors. His impact has transcended geographical boundaries, leaving a mark on projects in the United States and the Gulf region, often collaborating with Fortune 500 companies. Beyond his roles, Adnan is a dedicated educator, sharing his insights and knowledge as a trainer. He also passionately advocates for technology, frequently engaging with the community through speaking engagements in various forums. His multifaceted contributions exemplify his dedication to the tech field and his role in driving its evolution.

Leave a Reply