Getting error at folder level link

Raki 481 Reputation points
2022-02-17T19:39:58.537+00:00

Hello,
We have a external SP online facing site, where external user can upload documents into library but We don't want to allow them to edit file in the browser rather they will need to download file locally to edit and then upload again. so far i am close to fulfill requirements using below Json code with Calculated column but problem is with folder, when i am clicking the link at folder level, its just throwing the error "Sorry something went wrong. File not found". is there anyway we could tweak the below code and put some condition if there is folder don't do anything rather than getting the error.

Thanks in advanced.

FYI, i am following article from this link: https://natechamberlain.com/2021/06/19/how-to-create-one-click-direct-download-links-in-modern-sharepoint-online-libraries/

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "[$FileLeafRef]",
  "attributes": {
    "target": "_blank",
    "href": "=@currentWeb+'/_layouts/15/download.aspx?sourceurl='+[$FileRef]"
  }
}
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,575 questions
{count} votes

Accepted answer
  1. Echo Du_MSFT 17,156 Reputation points
    2022-02-18T07:37:48.343+00:00

    Hi @Raki ,

    Welcome to Q&A Forum!

    According to my understanding, FileRef and FileLeafRef are built in fields of SharePoint.

    FileLeaRef: Identifies a field that contains information about the server-relative URL for the file node that is associated with the specified SharePoint Foundation object.

    FileRef: Identifies a field that contains information about the server-relative URL for the specified SharePoint Foundation object.

    This JSON only works at the document level and not at the folder level. So when you clicking the link at folder level, it's normal to throw an error.

    Thanks,
    Echo Du

    =======================================
    Update Answer ====================================

    Hi @Raki ,

    Please follow the steps:

    1.Create a Single line of text column named [Download]

    2.Use the below JSON formatting for [Download] column

    {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",  
      "elmType": "a",  
      "txtContent": "[$FileLeafRef]",  
      "style": {  
        "cursor": "pointer",  
        "visibility": "=if(((indexOf([$ContentTypeId],'0x0120')) == 0),'hidden', 'visible')"  
      },  
      "attributes": {  
        "target": "_blank",  
        "href": "=@currentWeb+'/_layouts/15/download.aspx?sourceurl='+[$FileRef]"  
      }  
    }  
    

    177047-json1.jpg

    177090-json2.jpg

    Thanks,
    Echo Du

    ====================================

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.