"file download" dialog box appears twice

L

L. Scott M.

I am invoking a file download using the following code:

Response.Clear();

Response.AddHeader("Content-Disposition", "attachment; filename=" +
downloadFile.Name);
Response.AddHeader("Content-Length", downloadFile.Length.ToString());

Response.ContentType = "application/octet-stream";

Response.WriteFile(downloadFile.FullName);

Response.End();

This works with one issue. The user is provided with the "File
Download" dialog box that provides them with the options (Open, Save,
Cancel, More Info) twice, forcing the user to click on "Open" twice.

There is one difference, the first time that the "File Download"
appears the check box "Always ask before opening this type of file" is
disabled and has a check in it. The second time it is enabled and the
status version is displayed behind the prompt. Clicking "Open" the
second time opens the file.

What would cause this behaviour - we have another application developed
in VB Visual Studio 2003 and the "File Download" works as expected
(first time).

Second thing where can one find documentation that describes the
available options for the "Response" (AddHeader, ContentType). The
documentation that I have found leaves much to be desired.

TIA
Scott M.
 
L

L. Scott M.

A few more items we are using .NET 2.0 and are trying to get the server
to provide the files to be uploaded - the files do not reside in an
ASPNET directory.
 
D

Dave Sexton

Hi Scott,

Have you tried the following code instead?

Response.Redirect(downloadFile.FullName)
Second thing where can one find documentation that describes the
available options for the "Response" (AddHeader, ContentType). The
documentation that I have found leaves much to be desired.

IANA MIME Media Types:
http://www.iana.org/assignments/media-types/

I think the user agent can choose what is acceptable, so just in case don't
assume that you can always use anything in the list.
 
L

L. Scott M.

Dave,

Thanks for the "Redirect", it opens the document immediately.

We were trying to have the prompt (file download dialog box), but
having our users push "Open" or "Save" twice is at minimum sloppy.

Will check out the site: http://www.iana.org/assignments/media-types/
if our "security" will let me - or - maybe their site is down
temporarily...... d:}

Thanks again,
Scott 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

Top