C
Carlos Lozano
Hello,
I have the following section of code in a popup window that is opened from
other page when clicking a button:
The downloadFile method is called from the Page_Load Event.
private void downloadFile(string filename)
{
Response.ClearHeaders();
Response.ClearContent();
// set the http content type to "APPLICATION/OCTET-STREAM
Response.ContentType = "APPLICATION/OCTET-STREAM";
// initialize the http content-disposition header to
// indicate a file attachment with the default filename
// "myFile.txt"
//String disHeader = "Attachment; Filename=\"" + filename +
"\"";
string disHeader = "Attachment; Filename=" + filename;
Response.AppendHeader("Content-Disposition", disHeader);
// transfer the file byte-by-byte to the response object
System.IO.FileInfo fileToDownload = new
System.IO.FileInfo(Server.MapPath("Downloads") + "\\" + filename);
Response.Flush();
Response.WriteFile(fileToDownload.FullName);
Response.End();
}
This code works okay when running locally (http://localhost/site). If I try
to run it on a server in the internet (http://server/site) it does not show
the file download dialog.
The popup window is shown very fast, then it is closed right away.
Any ideas? Is it a security issue?
Thank you,
Carlos
I have the following section of code in a popup window that is opened from
other page when clicking a button:
The downloadFile method is called from the Page_Load Event.
private void downloadFile(string filename)
{
Response.ClearHeaders();
Response.ClearContent();
// set the http content type to "APPLICATION/OCTET-STREAM
Response.ContentType = "APPLICATION/OCTET-STREAM";
// initialize the http content-disposition header to
// indicate a file attachment with the default filename
// "myFile.txt"
//String disHeader = "Attachment; Filename=\"" + filename +
"\"";
string disHeader = "Attachment; Filename=" + filename;
Response.AppendHeader("Content-Disposition", disHeader);
// transfer the file byte-by-byte to the response object
System.IO.FileInfo fileToDownload = new
System.IO.FileInfo(Server.MapPath("Downloads") + "\\" + filename);
Response.Flush();
Response.WriteFile(fileToDownload.FullName);
Response.End();
}
This code works okay when running locally (http://localhost/site). If I try
to run it on a server in the internet (http://server/site) it does not show
the file download dialog.
The popup window is shown very fast, then it is closed right away.
Any ideas? Is it a security issue?
Thank you,
Carlos