Renaming file on-fly
Date: 06/13/08
(Asp Dot Net) Keywords: browser, web
Hello,
I do have a file on web server, let's say 123.zip
When I am redirecting user to it, browser opens Save dialog and puts that name by default: 123.zip. Is there any way to change that name to, let's say 456.zip?
File 123.zip stays on server as 123.zip, but user sees it as 456.zip.
One of the known ways is:
Byte[] data = System.IO.File.ReadAllBytes(sFullName); // 123.zip
Response.AddHeader("Content-Disposition", "attachment; filename=456.zip");
Response.OutputStream.Write(data, 0, data.Length);
Response.End();
But in this case I have to read the whole file first and then stream it out. Works fine with small files, but 123.zip could be huge. Then browser freezes and ends by timeout.
Thank you.
Source: http://community.livejournal.com/aspdotnet/98705.html