So on my download page I have:
protected void Page_Load(object sender, EventArgs e)
{
String filepath =
Request.Params.Get("Author") + "-" + Request.Params.Get("Title") + ".mp3";
if
(filepath.Length != 0)
{
Stream readStream =
MusicManager.GetSong(Int32.Parse(Request.Params.Get("file")));
int Length =
256;
Response.Clear();
Response.ContentType =
"application/octet-stream";
Response.AddHeader("Content-Disposition",
"attachment; filename=\"" + filepath + "\"");
Response.Flush();
Byte[]
buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0,
Length);
while (bytesRead > 0)
{
Response.OutputStream.Write(buffer,
0, bytesRead);
bytesRead = readStream.Read(buffer, 0,
Length);
}
Response.End();
readStream.Close();
}
}
Of course I have a page that sends in the query string with the necessary info
This seems all simple when it starts working, but it took me 2 hours to get the file to download correctly.
1 comment:
Thaanks for this
Post a Comment