M
m.a
Hello,
I have a web page that when user clicked on a button, it would create a
send a file to use so he can save it on his computer.
The code that I wrote is as follow:
protected void DownloadBtn_Click(object sender, EventArgs e)
{
string FileNameNoSpace = "test_file.ext";
string FilePathName = Server.MapPath(@"DownloadTemp\" + FileNameNoSpace);
CreateFile( FilePathName);
FileInfo TargetFile = new FileInfo(FilePathName);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" +
TargetFile.Name);
Response.AddHeader("Content-Length", TargetFile.Length.ToString());
Response.WriteFile(TargetFile.FullName);
Response.End();
}
void CreateFile(string Route_key, string FilePathName)
{
TextWriter tw = new StreamWriter(FilePathName);
// write a line of text to the file
tw.WriteLine("this file created on" + DateTime.Now);
for (int i = 0; i < 1000; i++)
{
tw.WriteLine("some data could be added here (line = "+i.ToString()+")");
}
// close the stream
tw.Close();
}
when I run this code in MSVC, it works correctly. After I pressed DownLoad
button, I get a save dialog and i can save the generated file but when I am
doing the same in IIS, after clicking the Download button, I will get a
blank screen.
Any help appreciated.
Regards
I have a web page that when user clicked on a button, it would create a
send a file to use so he can save it on his computer.
The code that I wrote is as follow:
protected void DownloadBtn_Click(object sender, EventArgs e)
{
string FileNameNoSpace = "test_file.ext";
string FilePathName = Server.MapPath(@"DownloadTemp\" + FileNameNoSpace);
CreateFile( FilePathName);
FileInfo TargetFile = new FileInfo(FilePathName);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" +
TargetFile.Name);
Response.AddHeader("Content-Length", TargetFile.Length.ToString());
Response.WriteFile(TargetFile.FullName);
Response.End();
}
void CreateFile(string Route_key, string FilePathName)
{
TextWriter tw = new StreamWriter(FilePathName);
// write a line of text to the file
tw.WriteLine("this file created on" + DateTime.Now);
for (int i = 0; i < 1000; i++)
{
tw.WriteLine("some data could be added here (line = "+i.ToString()+")");
}
// close the stream
tw.Close();
}
when I run this code in MSVC, it works correctly. After I pressed DownLoad
button, I get a save dialog and i can save the generated file but when I am
doing the same in IIS, after clicking the Download button, I will get a
blank screen.
Any help appreciated.
Regards