1

I have a file stored in server and I need to download it to my local folder. Currently, it gives me the download prompt but I need to save the file automatically without any prompt to the specified folder path. How can I do that?

string path = @"C:\tmp";
string pathstr = Path.Combine(path, "JobData", "JSAttachments", mydate, lbljsno.Text);
Directory.CreateDirectory(pathstr);
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
Response.WriteFile(Path.Combine(pathstr,filename));
Response.End();
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
batwing
  • 257
  • 1
  • 8
  • 22
  • 4
    If the client is a web browser, you can't make the web browser behave differently than intended. Browsers won't let a website just push a file without any user interaction (highly exploitable). – Eric J. Feb 12 '18 at 03:07

1 Answers1

2

How a client program wishes to handle files is up to it, and it alone.

If the server could just dictate a file should be stored anywhere, this would be a huge security risk. Which is why even with our primitive ideas about the internet back in 1980 we never were stupid enough to allow that.

If you can get the clients user to install a program on their machine, there are workarounds. But anything less is simply impossible and that is good so.

Graham
  • 7,431
  • 18
  • 59
  • 84
Christopher
  • 9,634
  • 2
  • 17
  • 31