I am trying to programmatically download a file by clicking a link on my site (this is a .doc file sitting on my web server). This is my code:
string File = Server.MapPath(@"filename.doc"); string FileName = "filename.doc"; if (System.IO.File.Exists(FileName)) { FileInfo fileInfo = new FileInfo(File); long Length = fileInfo.Length; Response.ContentType = "Application/msword"; Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name); Response.AddHeader("Content-Length", Length.ToString()); Response.WriteFile(fileInfo.FullName); }
This is in the buttonclick event handler. Well, I could do something with the file / file code to make it tidier, but when I click the button, the page refreshes. On the local host, this code works fine and allows me to upload the file in order. What am I doing wrong?
thanks
dotnetdev
source share