I am using the following code in a control event handler on a control in my module to add a document to the response as an attachment:
FileInfo fi = new FileInfo(fullPath);
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fi.Name + "\"");
Response.AddHeader("Content-Length", fi.Length.ToString());
byte[] buffer = new byte[1024];
long byteCount;
FileStream inStr = File.OpenRead(fullPath);
while ((byteCount = inStr.Read(buffer, 0, buffer.Length)) > 0)
{
if (Response.IsClientConnected)
{
Response.OutputStream.Write(buffer, 0, (int)(byteCount));
Response.Flush();
}
else
break;
}
inStr.Close();
I've been using this snippet for years with no problems. However, in the DNN environment I see problems. First, with PDF files, Acrobat (various versions on various machines) refuses to directly open the document. If I save it to the local drive and open it, it's fine. Otherwise, Acrobat claims it can not find the document after it downloads to temporary internet files location.
With other file types (Excel), it opens directly with no problems, but the next postback on the page hangs up. Waving flag, no action. Cancelling that and trying again the page starts working fine again.
In a non-DNN environment, I add a Response.End() call to ensure the response is done, but not in DNN (where there may be other things happening on the page).
Help?
Thanks,
John H.