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

  • Thread starter Thread starter Elrey Ronald V.
  • Start date 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)
 
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
 
Back
Top