HELP: How to I download a file without viewing it in ASP.NET?

  • Thread starter Elrey Ronald V.
  • Start date
E

Elrey Ronald V.

I need to download a file like MS Word doc
from a web form without viewing it. Something
that goes directly to the 'Save As' dialog.

Right now the browser takes over the displays
the document.

Is this possible?

TIA

(e-mail address removed)
 
C

Charles Rumbold

This is what I do:

// see if s/b downloaded rather than viewed

if( download )

{

Response.AddHeader("Content-Disposition",

"attachment; filename=\"" + theDocument.OriginalFileName + "\"" );

}

// make the reposnse

Response.Clear();

Response.ContentType = theDocument.FileType;

Response.Flush();

Response.WriteFile(theDocument.StoredFilePath);

Response.End();


'download' is a boolean extracted from the query string. Setting the
Content_Disposition and attachment is sufficient to cause the download
save as dialog to open (in IE6 anyway), otherwise it will attempt to
view it in IE6, if no viewer is found in will then download anyway.

HTH
Charles
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top