question

ShelbyStone-4626 avatar image
0 Votes"
ShelbyStone-4626 asked ShelbyStone-4626 answered

linking a document from a library to a list

I have a SharePoint library where I upload documents and another list where I would like to link those documents to rows. Here are the steps I am taking:

  1. I upload a document into the library and it gives me a simple link "doc1.pdf" in the column. The URL, when you hover over the link, points to the actual document but the link itself in the library column is short and simple and does not have the entire http://www.blahblah.com/doc1.pdf

  2. I export this library to Excel

  3. The link in the column shows "doc1.pdf" but, when you hover over it, shows that it points to the correct location. If I were to Edit Hyperlink in Excel, it shows the whole URL in the 'Address' and doc1.pdf in the 'Text to Display'.

  4. I then open the list in Quick Edit and attempt to do a simple copy/paste of the URL "doc1.pdf" from the exported library in Excel into the list in SharePoint.

  5. All that copies over is text "doc1.pdf" and no link. The column is Enhanced Rich text. If I create a hyperlink column, then the link simply shows an error because "doc1.pdf" is not a link.

How do I quickly and easily copy the actual LINK for "doc1.pdf" from the library into the list without have to edit each and every link in Excel? I have over 1,000 of these links to copy over.

3rd party or external software is not an option, unfortunately,



office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JoyZ avatar image
0 Votes"
JoyZ answered JoyZ commented

Hi @ShelbyStone-4626,

Instead of copying the direct url from the excel file, we can use pnp powershell to copy all file links from the library to the list:

 $SiteUrl="https://tenant.sharepoint.com/sites/Team1"
 $UserName="julie@tenant.onmicrosoft.com"
 $cred = Get-Credential -UserName $UserName -Message "Please enter password for $UserName"
 Connect-PnPOnline -Url $SiteUrl -Credentials $cred
    
 $SourceDoc="Doc38"
 $Targetlist = "list38"
    
 #Get All Items from the list - In batches of 500
 $ListItems = Get-PnPListItem -List $SourceDoc -PageSize 500
    
 #Loop through List Items and Get File URL
 $Results=@()
    
 ForEach($Item in $ListItems)
 {
     $link='';
     $Results += New-Object PSObject -Property @{
     FileName = $Item.FieldValues['FileLeafRef']
     FileURL = $Item.FieldValues['FileRef']
    
     }
       
    
 $SiteString = 'https://tenant.sharepoint.com' + $Item.FieldValues['FileRef']
    
 $link+="<a href='"+$Item.FieldValues['FileRef']+"'>"+ $SiteString +"</a>";
    
 Add-PnPListItem -List $Targetlist -Values @{"Enhancedrichtext" = $link}
    
 }
    
 $Results

Please remember to change the tenant name,site url,username,library name and list name for yourself.

Simple test for your reference:

My document library:

78678-image.png

After running the powershell:

78679-image.png


If an Answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (14.1 KiB)
image.png (15.4 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ShelbyStone-4626,

Do you have any progress on this issue?

Please remember to update this thread if you need further assistance.

0 Votes 0 ·
ShelbyStone-4626 avatar image
0 Votes"
ShelbyStone-4626 answered

This worked, thanks!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.