Howto open a file dialogbox (Save As) when using WriteFile

  • Thread starter Thread starter Anders
  • Start date Start date
A

Anders

Hi,

This is the code I am using:

string filepath = "Themes/img/logo.rar";

string filename = System.IO.Path.GetFileName(filepath);
Response.Clear();
Response.ContentType = "application/zip";

Response.AddHeader("Content-Disposition", "attachment; filename=" +
filename);
Response.Flush();
Response.WriteFile(filepath);

Instead of the choice of saving the file its content is output in the
browser.

Thanks in advance,
Anders
 
Hi,

Did you try Response.BinaryWrite instead of Response.WriteFile()?

Hi,

This is the code I am using:

string filepath = "Themes/img/logo.rar";

string filename = System.IO.Path.GetFileName(filepath);
Response.Clear();
Response.ContentType = "application/zip";

Response.AddHeader("Content-Disposition", "attachment; filename=" +
filename);
Response.Flush();
Response.WriteFile(filepath);

Instead of the choice of saving the file its content is output in the
browser.

Thanks in advance,
Anders
 
If I use BinaryWrite ill have to change all the code, specify the filepath
from the root and give ASPNET access to the path which I dont know how to do
in WinXP.

Best,
Anders
 
I added Reponse.Buffer = true just before the Response.Clear(); and now it
works!

Cheers,
A
 

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

Back
Top