简体   繁体   中英

Get the URL behind link items in SharePoint document library via REST API

I have a custom web part that I can connect to different data sources (eg SharePoint Document Libraries). Then I can map the item properties from that document library to one of my different view templates.

The problem is when I add a Link item (external Url) in that document library, I cannot find an item property that stores that external Url.

在此处输入图片说明

Right now I get the item properties via SharePoint REST API. I checked the values for FileRef and EncodedAbsUrl , but these are URLs pointing to the SharePoint document library file, and not to the external URL.

After some investigations, I've seen in the dev tools (F12) Network tab, there's a call to https://{siteurl}/_api/SP.Utilities.ShortcutLink.GetShortcutLink(@a1)?@a1={siteUrl}/Shared%20Documents/www.dummysite.com.url which will retrieve the actual linked external URL, but this not a good option for me, since making another REST call for each item will impact my performance.

So is there any item property that I could expand to get the external URL, via REST API?

You can extract properties for specific item and then select "vti_x005f_shortcuturl" property. Eg

    https://<your site url>/_api/web/lists/getbytitle("your library 
    name")/items(1)/properties?$select=vti_x005f_shortcuturl 

If you don't have item id in advance then first get only Id's from document library using rest api in first call as you are concerned with performance if you have to call rest api twice, and then call above api for each item ID with required properties only. In above example it will return url behind link for first item ("/items(1)/") if available.

SharePoint Online returns nothing for Properties/vti_x005f_shortcuturl

However, I was able to retrieve a URL "/sites/sitename/.../surprisedPikachu.jpg" by expanding "File" and selecting "File/ServerRelativeUrl".

$expand=File&$select=*,File/Name,File/ServerRelativeUrl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM