mardi 26 novembre 2019

Download a file (.xlsx) from Server local directory ( D:\..etc etc)

there are multiple questions on that thema but none really covered my question.

I want a button to download( or open in new tab) a file from D:\ directory on the server.

I have a file created in controller

    var filePath = HttpContext.Current.Server.MapPath("~/" + "StatisticReports");
    Directory.CreateDirectory(filePath); 

this path by looking on server local files is in D:....\StatisticReports

I tried in .ts file to run this:

    var ul = "file:///D:/nameOfApplication/etc..et..etc/Report.xlsx";
    var win = window.open(ul, '_blank');
    win.focus();

The result is a blank new tab. I am aware that because of Rights and security reasons I can't access the server directory. Can someone link me a code example with an alternative option?

I read somewhere that it is possible to give the user the option to download and he can decide himself to accept it or not by "save as", maybe this could be a solution? (If yes, some code would be really appreciated).

Thanks a lot for your help. enter code here




Aucun commentaire:

Enregistrer un commentaire