B
Bob Murdoch
I'm using the following to send a binary file to a user:
Response.AddHeader('Content-Disposition','attachment;filename=' +
Request('FileName') + ';');
var vType = 'application/octetstream';
var vFileName = String(Request('FileName')).toLowerCase();
if (vFileName.indexOf('.xls') > -1)
vType = 'application/vnd.ms-excel';
if (vFileName.indexOf('.csv') > -1)
vType = 'application/vnd.ms-excel';
else if (vFileName.indexOf('.pdf') > -1)
vType = 'application/pdf';
else if (vFileName.indexOf('.zip') > -1)
vType = 'application/zip';
else if (vFileName.indexOf('.doc') > -1)
vType = 'application/vnd.msword';
Response.ContentType = vType;
Response.Expires = 0;
var vStream = Server.CreateObject("ADODB.Stream");
vStream.Open();
vStream.Type = 1; //binary
vStream.LoadFromFile(vPath + Request('TempFile')); //must be full server
path and file name
Response.AddHeader('Content-Length', vStream.Size);
Response.BinaryWrite(vStream.Read());
vStream.Close;
vStream = null;
Response.End;
I have verified that the vStream.Size is correct at that point in the
script. However, in the IE download dialog, it only says "Estimated Time
Left: not known". I have also tried "AddHeader('Content-Length',
vStream.Size.ToString) just in case there was some conversion problem with
the size, but there was no change.
Is there some other way of telling the browser how big the file is?
tia,
Bob M..
Response.AddHeader('Content-Disposition','attachment;filename=' +
Request('FileName') + ';');
var vType = 'application/octetstream';
var vFileName = String(Request('FileName')).toLowerCase();
if (vFileName.indexOf('.xls') > -1)
vType = 'application/vnd.ms-excel';
if (vFileName.indexOf('.csv') > -1)
vType = 'application/vnd.ms-excel';
else if (vFileName.indexOf('.pdf') > -1)
vType = 'application/pdf';
else if (vFileName.indexOf('.zip') > -1)
vType = 'application/zip';
else if (vFileName.indexOf('.doc') > -1)
vType = 'application/vnd.msword';
Response.ContentType = vType;
Response.Expires = 0;
var vStream = Server.CreateObject("ADODB.Stream");
vStream.Open();
vStream.Type = 1; //binary
vStream.LoadFromFile(vPath + Request('TempFile')); //must be full server
path and file name
Response.AddHeader('Content-Length', vStream.Size);
Response.BinaryWrite(vStream.Read());
vStream.Close;
vStream = null;
Response.End;
I have verified that the vStream.Size is correct at that point in the
script. However, in the IE download dialog, it only says "Estimated Time
Left: not known". I have also tried "AddHeader('Content-Length',
vStream.Size.ToString) just in case there was some conversion problem with
the size, but there was no change.
Is there some other way of telling the browser how big the file is?
tia,
Bob M..