aspdotnetuser
Programmer
Hi,
I want to allow the user to download a .bmp file to their desktop, and I have the code working for this but when the file is downloaded it cannot be opened - why is this? Can anyone tell me what I am doing wrong? Here is the code
(exectuted when user clicks download button)
[blue]
String fileName;
fileName = ReceiptID.Remove(0, 6);
string url = " + fileName;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
int bufferSize = 1;
[red]//Initialize the output stream[/red]
Response.Clear();
Response.AppendHeader("Content-Disposition:", "attachment; filename=download.jpg");
Response.AppendHeader("ContentLength",resp.ContentLength.ToString());
Response.ContentType = "application/download";
[red]//Populate the output stream[/red]
byte[] ByteBuffer = new byte[bufferSize + 1];
MemoryStream ms = new MemoryStream(ByteBuffer, true);
Stream rs = req.GetResponse().GetResponseStream();
byte[] bytes = new byte[bufferSize + 1];
while (rs.Read(ByteBuffer, 0, ByteBuffer.Length) > 0)
{
Response.BinaryWrite(ms.ToArray());
Response.Flush();
}[/blue]
I want to allow the user to download a .bmp file to their desktop, and I have the code working for this but when the file is downloaded it cannot be opened - why is this? Can anyone tell me what I am doing wrong? Here is the code
(exectuted when user clicks download button)
[blue]
String fileName;
fileName = ReceiptID.Remove(0, 6);
string url = " + fileName;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
int bufferSize = 1;
[red]//Initialize the output stream[/red]
Response.Clear();
Response.AppendHeader("Content-Disposition:", "attachment; filename=download.jpg");
Response.AppendHeader("ContentLength",resp.ContentLength.ToString());
Response.ContentType = "application/download";
[red]//Populate the output stream[/red]
byte[] ByteBuffer = new byte[bufferSize + 1];
MemoryStream ms = new MemoryStream(ByteBuffer, true);
Stream rs = req.GetResponse().GetResponseStream();
byte[] bytes = new byte[bufferSize + 1];
while (rs.Read(ByteBuffer, 0, ByteBuffer.Length) > 0)
{
Response.BinaryWrite(ms.ToArray());
Response.Flush();
}[/blue]