Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
3.33/5 (2 votes)
See more:
Hi,

I am trying to download an exe file from my asp.net application where hosted in the IIS but it downloading the default download path. I want to download the exe in specific folder in the client machine (ie. D:\Sample\Test.exe) instead of downloading C:\user\downloads\Test.exe

Thanks in Advance
Posted
Updated 12-Jan-15 19:51pm
v2
Comments
BulletVictim 13-Jan-15 1:51am    
As far as I know this cannot be set from server side to specify on the client side, this is mostly to do with security restrictions from the browsers.
To specify the path of where the file downloads is settings mostly on the client's browser that needs to be changed. With chrome you can specify that it asks you where to download the file to each time it downloads something, IE you have the option to save as.
This is similar to launching an application from the server on the client station (although with ActiveX object you can do this, but only in IE). It is a major security risk to allow client stations to be accessed from the server via code.
Best suggestion would be to have the client save the files to the desired location manually.
ZurdoDev 15-Jan-15 8:23am    
How are you trying to download? With code? Or clicking a link? You haven't told us enough info.

Use FtpWebRequest class and you can state where your file should go to.
See here[^] a small example
 
Share this answer
 
C#
string filename = "yourfilename";
if (filename != "")
{
    string path = Server.MapPath(filename);
    System.IO.FileInfo file = new System.IO.FileInfo(path);
    if (file.Exists)
    {
         Response.Clear();
         //Content-Disposition will tell the browser how to treat the file.(e.g. in case of jpg file, Either to display the file in browser or download it)
         //Here the attachement is important. which is telling the browser to output as an attachment and the name that is to be displayed on the download dialog
         Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
         //Telling length of the content..
         Response.AddHeader("Content-Length", file.Length.ToString());

         //Type of the file, whether it is exe, pdf, jpeg etc etc
         Response.ContentType = "application/octet-stream";

         //Writing the content of the file in response to send back to client..
         Response.WriteFile(file.FullName);
         Response.End();
    }
    else
    {
         Response.Write("This file does not exist.");
    }
}
 
Share this answer
 
Comments
Member 15922520 29-Sep-23 8:57am    
no
You can't do this for security reasons. If a server could push files to locations on the hard-drive it could overwrite config files, password files etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900