0

In Kentico, how can make it possible for site users to see and download files uploaded by other users through a form?

I make a form in Kentico CMS. Users can fill and submit it properly. My form has an upload file field. I made a new page to show the content of the submitted forms. For this, I use a "Query Repeater with effect". It seems the Query works well. I write a Transformation to show each record in a table format. All records and fields appear well except the file field. I can not find a way to generate a link of uploaded files to assign it to the href attribute of a link tag. I use code like this

<a href="https://example.com/CMSPages/GetBizFormFile.aspx?filename=<%# Eval("UploadFile1") %>"> Download File</a>"

The problem with this code is the <%# Eval("UploadFile1") %> returns a string like this

94e5b02d-1bcd-4341-9930-6e5ef1029d8b.pdf/MyFileName.pdf

How can I solve this problem?

rocky
  • 7,506
  • 3
  • 33
  • 48

2 Answers2

0

When using the /CMSPages/GetBizFormFile.aspx you need to supply the file name and site name as the query string parameters. The file name is actually the GUID of the file + the extension. So, the link should look like this:

~/CMSPages/GetBizFormFile.aspx?filename=3560f3ed-6a12-444e-9fc6-2447fc903a23.jpg&sitename=SiteName

The thing here is that the GetBizFormFile is checking the access - user must be logged in, editor and must have permissions for forms module assigned.

If you want to create a public accessible link, you will need to compose the link directly to the disk location of the file (assuming that the folder on disk is not secured). The default location is ~//BizFormFiles. You can customize the location in Settings -> System -> Files -> Custom form files folder. This means, that using the GUID stored within the file upload field, you can compose the link like:

~/SiteName/BizFormFiles/3560f3ed-6a12-444e-9fc6-2447fc903a23.jpg
jurajo
  • 937
  • 5
  • 5
0

One of my friend suggested a solution that is works well!

1- at the first get the access to Everyone to read form records. Applications>Permissions>Module>forms

get the access to Everyone

2- the code for transformation:

<asp:PlaceHolder ID="ph1" runat="server" Visible='<%# IfEmpty(Eval("UploadFile1"), false, true) %>'>
      <br>
      <a style="color:blue;font-weight:bolder" href=<%# "https://example.com/CMSPages/GetBizFormFile.aspx?filename=" + Eval("UploadFile1").ToString().Split('/')[0] %>>Download File: <%# Eval("UploadFile1").ToString() == "" ? "a" : Eval("UploadFile1").ToString().Split('/')[1] %></a>
</asp:PlaceHolder>

the first line is for show nothings if there is not any uploaded file.