G
Grant Merwitz
Hi
I am trying to make a page to allow users to download files.
These files are not directly accessible through IIS, the code accesses the
file then streams this to the user.
One method i have tried, is to stream the file to the user.
Like so:
using(System.IO.FileStream fs = new System.IO.FileStream("c:\test.txt",
System.IO.FileMode.Open))
{
byte[] Buffer = new byte[(int)fs.Length];
fs.Read(Buffer, 0, (int)fs.Length);
//Write it Out
Response.CearContent();
Response.AppendHeader("Content-Disposition",
"inline;filename=test.txt");
Response.BinaryWrite(Buffer);
}
Now this works fine for text types (Word Doc, Pdf, TextFile),
but does not work with all formats (.zip, .wma)
I can right click the link that redirects to this page, but i have to change
the extension from .htm to is real type, and then it works fine.
Is this the right way to do this? Is there an easier way?
How can stream the correct file type?
TIA
I am trying to make a page to allow users to download files.
These files are not directly accessible through IIS, the code accesses the
file then streams this to the user.
One method i have tried, is to stream the file to the user.
Like so:
using(System.IO.FileStream fs = new System.IO.FileStream("c:\test.txt",
System.IO.FileMode.Open))
{
byte[] Buffer = new byte[(int)fs.Length];
fs.Read(Buffer, 0, (int)fs.Length);
//Write it Out
Response.CearContent();
Response.AppendHeader("Content-Disposition",
"inline;filename=test.txt");
Response.BinaryWrite(Buffer);
}
Now this works fine for text types (Word Doc, Pdf, TextFile),
but does not work with all formats (.zip, .wma)
I can right click the link that redirects to this page, but i have to change
the extension from .htm to is real type, and then it works fine.
Is this the right way to do this? Is there an easier way?
How can stream the correct file type?
TIA