IIS ASP - Save As Type list

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > May 2007 > Save As Type list





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Save As Type list
Bob Murdoch

2007-05-24, 7:17 pm

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;


Adrienne Boswell

2007-05-25, 7:16 am

Gazing into my crystal ball I observed "Bob Murdoch"
<ram_re_move_5@erols.com> writing in
news:eLNYLgknHHA.4552@TK2MSFTNGP04.phx.gbl:

> 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.

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Anthony Jones

2007-05-25, 7:16 am


"Bob Murdoch" <ram_re_move_5@erols.com> wrote in message
news:eLNYLgknHHA.4552@TK2MSFTNGP04.phx.gbl...
> 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.





Bob Murdoch

2007-05-25, 1:18 pm

"Anthony Jones" wrote:
>
>
>
> 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..


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com