Save As Type list

B

Bob Murdoch

I am sending an attachment to a user with the following code. This
successfully prompts the user to Save or Open, provides the correct file
name, and displays "Microsoft Excel Worksheet" as the Type.

However, when the user clicks "Save", the "Save As File Type" in the
resulting dialog displays 'HTML Document'. There is only one other entry in
the list - "All Files". How can I modify the code to display "Excel
Document" (or some such) in the "Save As Type" list?

thanks,

Bob M..



var vPath = Server.MapPath('/server/files') + '\\';

Response.AddHeader('Content-Disposition','attachment;filename=' +
Request('FileName') + ';');

var vType = 'application/octetstream';
var vFileName = String(Request('FileName')).toLowerCase();
if (vFileName.indexOf('.') > -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.AddHeader('Content-Type', vType);
Response.AddHeader('Pragma','no-cache');
Response.AddHeader('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.BinaryWrite(vStream.Read());
vStream.Close;
vStream = null;
Response.End;
 
A

Adrienne Boswell

I am sending an attachment to a user with the following code. This
successfully prompts the user to Save or Open, provides the correct
file name, and displays "Microsoft Excel Worksheet" as the Type.

However, when the user clicks "Save", the "Save As File Type" in the
resulting dialog displays 'HTML Document'. There is only one other
entry in the list - "All Files". How can I modify the code to display
"Excel Document" (or some such) in the "Save As Type" list?

IIRC, this is a browser/os issue.
 
A

Anthony Jones

Bob Murdoch said:
I am sending an attachment to a user with the following code. This
successfully prompts the user to Save or Open, provides the correct file
name, and displays "Microsoft Excel Worksheet" as the Type.

However, when the user clicks "Save", the "Save As File Type" in the
resulting dialog displays 'HTML Document'. There is only one other entry in
the list - "All Files". How can I modify the code to display "Excel
Document" (or some such) in the "Save As Type" list?

thanks,

Bob M..



var vPath = Server.MapPath('/server/files') + '\\';

Response.AddHeader('Content-Disposition','attachment;filename=' +
Request('FileName') + ';');

var vType = 'application/octetstream';
var vFileName = String(Request('FileName')).toLowerCase();
if (vFileName.indexOf('.') > -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.AddHeader('Content-Type', vType);
Response.AddHeader('Pragma','no-cache');
Response.AddHeader('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.BinaryWrite(vStream.Read());
vStream.Close;
vStream = null;
Response.End;

Use

Response.ContentType = vtype

Instead of AddHeader. ASP will set the content type by default to
text/html. If you use the AddHeader method you end up sending two
Content-Type headers. The browser is getting confused.

Similarly you should use:-

Response.Expires = 0
Response.CacheControl = 'no-cache; max-age=0'

Don't bother with the Pragma.
 
B

Bob Murdoch

Anthony Jones said:
Use

Response.ContentType = vtype
Response.Expires = 0
Response.CacheControl = 'no-cache; max-age=0'

Don't bother with the Pragma.

Thanks Anthony, that did the trick.

The strange thing is that the earlier code worked on IIS 5 on W2k, but it
wasn't until we moved to IIS 6 on W2k3 that this problem started happening.


Bob M..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top