downloading works in MSVC but not in IIS

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top