Save As Type list

Save As Type list

am 24.05.2007 23:09:28 von 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;filenam e=' +
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;

Re: Save As Type list

am 25.05.2007 09:42:49 von Adrienne Boswell

Gazing into my crystal ball I observed "Bob Murdoch"
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

Re: Save As Type list

am 25.05.2007 11:03:34 von Anthony Jones

"Bob Murdoch" 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;filenam e=' +
> 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.

Re: Save As Type list

am 25.05.2007 15:26:14 von Bob Murdoch

"Anthony Jones" wrote:
>
>> However, when the user clicks "Save", the "Save As File Type" in the
>> resulting dialog displays 'HTML Document'.>
>
>
> 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..