Copying the “normal” (classic) link of an item in SharePoint

Anoop
3 min readNov 13, 2018

In the modern list/library view, SharePoint provides you an option to “Copy Link” of a selected item (document/image/list item etc). This command works great when users want to share an item with others. The link provided by this command has some sort of complex Id in it which I think is related to sharing/permissions etc.

The problem

A client had a request wherein they wanted the normal/direct/classic link of the selected item and not the complex link generated by the Copy Link command. These links would then be used in classic content editor webparts. There are ways in which we can get the classic link. But those are a bit complex for an end user. Hence I developed an SPFx extension.

The solution

Command to copy the classic link

SPFx extensions are awesome and they make many of your tasks easier. The extension developed here adds a command, called “Copy classic link”, when an item is selected in a document library. Clicking on that command copies the actual/normal/classic link of the selected item to clip board and all you have to do is “Ctrl+V” to use it.

Code

The code for this is present in github in the PnP sp-dev-fx-extensions repository. Please follow the instructions in readme.md to test it first.

The library used to copy link to clipboard is “copy-to-clipboard” and the following code copies the link

After that the success message can either be displayed using toastr or sweetalert

Deployment

The PnP team produce great videos around SPFx. One of those videos shows how to deploy SPFx extensions globally (tenant wide). Here is the video.

The instructions in that video show how to deploy a sample SPFx extension and the same can be followed for the “Copy classic link” extension.

Changing alert style

After deployment the admin can choose whether the command should display sweetalert for success message or toastr notification. This can be done by navigating to the “Tenant wide extensions” list in the app catalog site and updating the “showToastr” component properties of “CopyClassicLink”

Setting “showToastr” to “yes” will show toastr notification

and setting “showToastr” to “no” will show sweetalert

--

--

Anoop

Microsoft MVP. M365 Developer Architect at Content+Cloud.