Domanda

I am developing a command set & looking for a way to get the Share URL of selected documents. I have tried these to get other urls.

event.selectedRows.getValueByName('.spItemUrl');
event.selectedRows.getValueByName('FileRef');

But I want the URL look like below, which we will get something when we Share or Copy Link:

https://contoso.sharepoint.com/:i:/s/Personal/EZtdo-T3MAtJldnaju5gtb4BBmXWDdNdljhdDywGBQJAgA?e=WYgQZ5

How to get this?

È stato utile?

Soluzione

To get the Share URL, you can use any of the 3 approaches mentioned below:

Option 1 - using ServerRedirectedEmbedUrl

You can make use the ServerRedirectedEmbedUrl to get the URL as below:

event.selectedRows.getValueByName('ServerRedirectedEmbedUrl');

Option 2 - using ?web=1 query string parameter

Another thing you can do is append the ?web=1 query string parameter and form the absolute url of the file.

const absoluteUrl:string = this.context.pageContext.site.absoluteUrl;

const relativeUrl:string = this.context.pageContext.site.serverRelativeUrl;

const docRelativeUrl:string = event.selectedRows[0].getValueByName('FileRef');

const docShareUrl = `${absoluteUrl}${docRelativeUrl.substr(relativeUrl.length)}?web=1`;

However, both above approaches have the document opening in a preview or read mode. I have noticed that the OOTB Share or Copy command generates the URL and when opened, the document is in edit mode.

So, to open it in edit mode, you can use option 3.

Option 3 - Open in edit mode

Here you need to form the url dynamically yourself as below:

The url format is: <Site URL>/_layouts/15/WopiFrame.aspx?sourcedoc=<Doc URL>&action=edit

const absoluteUrl:string = this.context.pageContext.site.absoluteUrl;

const docRelativeUrl:string = event.selectedRows[0].getValueByName('FileRef');

const docShareUrl = `${absoluteUrl}/_layouts/15/WopiFrame.aspx?sourcedoc=${docRelativeUrl}&action=edit`;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top