Link to Document not Valid - Unable to Download Document

Kim Driggers asked on May 4, 2016 15:55

I have a page that using a Smart Search filter and smart search page results. In the content tree, under that subsection, I am posting files and tagging and categorizing them. I closed the CMS.File and added additional fields so the user could add tags and categories on the form when adding a while.

The page renders the results with a link after the file name to Download. When the Download link is click there is an error message displayed and not file downloaded.

In the transformation I used this code:

 <tr>
        <td><%# GetSearchValue("FileName") %></td>
        <td><%# FormatDateTime(GetSearchValue("FileDate"), "MM/dd/yyyy") %></td>
        <td><a href="<%# GetAbsoluteUrl("/getattachment/" + GetSearchValue("FileAttachment")) %>" title="Download" target="_blank">Download</a></td>
      </tr>

The HTML envelope Content before is:

<table>
  <tr>
    <th>File</th>
    <th>Date</th>
    <th>Download</th>
  </tr>

the Content after is:

</table>

Any advice on how to correct the download link not working? Thanks in advance for reviewing.

Correct Answer

Jan Hermann answered on May 12, 2016 07:53

Please change it to:

<a href='/getattachment/<%# GetSearchValue("FileAttachment") %>/file.aspx' title="Download" target="_blank">Download</a>

0 votesVote for this answer Unmark Correct answer

Recent Answers


Kim Driggers answered on May 4, 2016 15:56

The content after actually display incorrectly when I posted this. Basically it should display in a table.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on May 4, 2016 16:26

Are the files that you are trying to get attachments or normal files in the content tree? Also, guessing that the fileattachment contains a guid, but can you verify that this is what is being displayed? Maybe post a link that this transformation is rendering so we can get a better sense of what could be happening.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on May 4, 2016 17:20 (last edited on May 4, 2016 17:23)

Next time please mark your code lines as block of code in the toolbar :) I have fixed it for now.

Anyway, you are mixing double quotes together without escaping them. Please try this instead:

<a href='/getattachment/<%# GetSearchValue("FileAttachment") %>/file.aspx' title="Download" target="_blank">Download</a>

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 4, 2016 19:12

Thanks for fixing my code. (I'm a newbie) The files are pdf, docx, etc. Normal files that would we used in an office environment. For example we would have a link that might say Project Initiation Policy (pdf) Download. Then from the download link they would be able to access the file.

Eventually the document repository would have numerous files so that someone could need for the file they are looking for by tag or category (i.e. policy, information technology, service request, new employee setup, etc.)

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 4, 2016 19:31

Jan,

I had the double quotes in correctly. When the url attempts to render the incorrect result is given. I get "404 error The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." The event log shows "page not found" So I'm thinking it's the way that I have the getattachment entered.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on May 5, 2016 10:11

What is the url? Could you please share some actual url that returns 404?

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 5, 2016 14:25

In the URL window the link renders http://localhost/Kentico_API/Document-Repository/getattachment/ (I'm using a test environment). The error is HTTP ERROR 404.0 - Not Found. The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. The event log shows event type Warning, source Application_Error, event code PAGENOTFOUND.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on May 8, 2016 21:18

Is this whole url? The interesting part starts after the getattachment handler. If there is nothing after that the link is corrupted and correctly returns 404.

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 9, 2016 15:11

Yes. This is the whole url. That's why I don't understand why the link is not rendering. From searching the posts it appears there are others that are having this same issue.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on May 10, 2016 14:34

It seems that you are not using my recommended code. Could you please make a screenshot of what you currently have in your transformation?

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 10, 2016 14:59 (last edited on May 10, 2016 15:10)

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 12, 2016 16:11

Thank You!!!! Yes! That Worked. Thank you so much!

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 13, 2016 20:28 (last edited on May 13, 2016 20:30)

"<a href='/getattachment/<%# GetSearchValue("FileAttachment") %>/file.aspx' title="Download" target="_blank">Download"

THis is code I am using that worked

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 19, 2016 15:56

So Jan, If I wanted to display the file type, how would I code that? I have duplicate documents with the same name. The only difference would be one would be .docx and one would be .pdf. Example: Sickleave.docx and Sickleave.pdf.

Is that something that would need to be coded in the transformation?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.