Link SharePoint List to a Document Library

SharePoint Lists are great for tracking activities. There are many scenarios where you may want to store a collection of documents for each List item. In this blog I explain how to use Column formatting to create the link to the documents related to a List item.

In this example, we have a List that will track enquires and a Library with a folder per enquiry. Each enquiry will have a unique number and the library will contain a folder with the same number. to keep it simple, I will use the Lists ‘Title’ field, but you could use a different value by adding a number generator or entering a unique value in the List form.

Steps

Create a List with the various fields you want e.g. details of the enquiry, type of enquiry, dates etc.

Create a PowerAutomate Workflow that creates a folder in the Document Library when a new item is added to the List. In this example, when an Item is created in “MyList”, the second step creates a folder in the “Clients” Library using the List items Title as the Folder name.

To create a hyperlink from a SharePoint List to the corresponding folder in a Document Library, follow these steps:

  • Add the following JSON column formatting to the column, replacing URL in the “href” line with your URL (Library URL)
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='http://xxxxxx.sharepoint.com/sites/sitename/libraryname/' + @currentField"
  }
}

Done! Now every time a new List item is created, Power Automate will create a folder using the List items Title as the folder name. The calculated column will contain a hyperlink, that takes you to the corresponding folder where you will see existing documents and can drag and drop other correspondence.

Creating an item in the SharePoint List for Joe Bloggs, creates a Hyperlink

Clicking the Link takes me to the Clients document library with a list of documents for the client.

I use this technique for various scenarios including, customer enquires, client folders, incident management and certification tracking.

I hope you find this helpful.

24 thoughts on “Link SharePoint List to a Document Library

  1. this worked perfectly, however for me the link in the list does not actually take me directly inside the corresponding folder, it just brings me to the document library itself. Is there a way to have the link bring me inside the correct folder?

  2. Hi Mary, the value in the List needs to be the name of the folder e.g. if the folder is called 12345 then the List needs to have the same value. The JSON formatting will append the value to the end of the URL. I hope that helps.

    1. I realized it was actually my URL that was the issue and it works now thank you. This was actually the most straightforward way to accomplish this task, after hours of attempting various methods that all ended in failure. The only thing I did not consider is that if I need to change the title of the list item for some reason, the folder name does not update automatically to match.

      1. Thanks for the update Mary, I am glad you resolved the issue. You are right about the title, in some scenarios you can use a different column to store the folder value. That works as long as the value is unique.

      2. Hi Mary, facing the same problem – could you tell me how you realized it was actually your URL? The values in my list are identical to the name of the folder I want to link to, yet the link doesn’t take me inside the corresponding folder.

        Many thanks in advance for your help!

      3. The URL is made up of the URL for the library + folder name
        In the JSON, I use append the folder name to the URL using the value in the column the formatting is applied to. So you need to check two things:
        – Is the value in the column the folder name
        – If the Document Library URL correct – https://tenantname.sharepoint.com/sites/sitename/libraryname

        You can test by manually creating the URL and pasting into the URL bar. If that doesn’t take you to the folder then the URL is incorrect

      4. Hello Mary,
        I hope you can help, I am struggling with the same thing you were, the link just takes me to the home page of the doc library. I want it to determine the title and open the folder named the same thing. Can you explain how you did that in more detail please?

    2. Is there a way to use JSON to derive the subfolder name (than hardcode it)? I have lots of sub folders and documents can move between the subfolders. I also need to use that path in a lookup field, possible? Prefer not to powerautomate.

  3. Hey Steve, this is fantastic – thanks for sharing. I found a problem when viewing the list via a “Calendar View”, in that the link loses it’s hyperlink ability and becomes raw text. Do you know if there’s a method to allow the hyperlink to also work in a Calendar View of the List?

      1. I managed to find time to look into this further – the best solution that I found was to use a Rich Text column, and to fill it with hyperlink details via Flow. (there’s a couple of other methods that half work too, but Rich Text worked the best).

        It would be useful if MS had a method of selecting an item in the Calendar view and having a small pop-up card with the event details. But still, having the entire Form slide in from the right, the hyperlink is displayed and clicks through as expected.

  4. Hi,

    I don’t want to use the automated part. But I do like to have an url to a sharepoint folder. What I did; I created a hyperlink column. Then I wanted to copy the folder location (url in the address bar) and paste it in this column. However, the URL is too long and cannot be placed in this field.

    Do you have an idea how to create an URL to a sharepoint folder?

  5. Did not work with @currentField, instead I had to use [$Title] and after the “Title” (=my entry in the list, which defined the name for the subfolder) there was an other big chunk of URL, so it I used ‘ + [$Title] + ‘. Then it worked fine.
    Brilliant way to tie lists and libraries! As the Title is likely some sort of identifier for a case, it is useful to enforce unique values, so at least no double entries.

    1. My URL to a certain folder has other big chunk of URL as well. Could you please paste the code that made it worked for you? Thanks.

  6. Hi Steve,

    Related to this but not exactly the same, do you know how to use JSON coding to link a specific document within a library to a lookup column in a list? If I have it as just a regular lookup column, it links to the item in the library and the document can only be accessed via the document ID. When the document ID is clicked, it downloads the document to the computer which I don’t want to happen. I found some JSON coding on another blog and attempted to modify it to what I need but I’m getting a “This site can’t be reached” error because it’s trying to add my document name into the site URL. Any help is appreciated!

    Current JSON coding:
    {
    “$schema”: “https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json”,
    “elmType”: “a”,
    “txtContent”: “@currentField.lookupValue”,
    “attributes”: {
    “target”: “_blank”,
    “href”: “=’SITE URL’ + @currentField.lookupValue”
    }
    }

    Kimberly

  7. This was a very helpful tip. As I am working with hundreds of thousands of documents in thousands of folders, I decided to nest them in a format like library/aa/bb/aabbcc where aabbcc is where the documents are and the first two parent folders are obviously the first and second set of 2 characters of that folder. there are a whole raft of functions you can use in creating your custom field HREF – so i did something like “href”: “=’http://xxxxxx.sharepoint.com/sites/sitename/libraryname/’ + substring (@currentField, 0,2) + ‘/’ + substring(@currentField, 2, 4) + ‘/’ + @currentField” which worked out perfectly. Here’s the reference I used: https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/formatting-syntax-reference

    1. That’s a great tip! Thanks for taking the time to post the comment, I am sure that will help other people too.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s