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`;