0

I try to download a file in javascript, passing filename from html

HTML:

 <img border="0" src="/Content/Images/Icons/color-16/disk-return-black.png" width="20" height="18" style="cursor: pointer" onclick="downloadDocFoto('@item.CaminhoDocFoto')" id="btnDownloadDocFoto_Contrato">

Javascript:

function downloadDocFoto(NomeDocFoto) {
    alert(NomeDocFoto);
    var url = '~/App_Data/uploads/' + NomeDocFoto + '';
}

the var url have the path where files stay, and the filename

CesarMiguel
  • 3,756
  • 4
  • 24
  • 34

1 Answers1

0

you can NOT access App_Data folder directly! This is made for security reasons. if you want to get files from it you have to write custom HttpHandler or Controller with appropriate Action

Romko
  • 1,808
  • 21
  • 27
  • Ok, i'll change. But who is the javascript code to download file? – CesarMiguel Nov 27 '13 at 17:07
  • it will point to, for example: /File/Get where File is controller and Get is action that writes file to response. How to do that? Search Google – Romko Nov 27 '13 at 17:08
  • see http://stackoverflow.com/questions/186062/can-an-asp-net-mvc-controller-return-an-image – Romko Nov 27 '13 at 17:10