470,849 Members | 1,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

File Download Functionality Different on Dev and Test Servers

Basically I have a link that opens my download page and the querystring
identifies the type of 'template' Excel spreadsheet has asked to download.
The download page reads the querystring, identifies the template required
then uses Response.AppendHeader to amend the response to create the file
download dialogue. On my local machine this works fine and the download
dialogue correctly identifies the file name and type attempting to be
downloaded. However, when this is ported to the Test web server the download
dialogue asks if I want to save or open the Download.aspx page, not the xls
file that should be targetted. To further confuse me, if you save this file,
open it in a text editor, remove the html elements of it, leave the encoded
elements, (square blocks, hex etc.), and save this as an xls file from the
text editor MS Excel opens the saved file correctly and it is in fact the
file that was attempted to be downloaded.

To me it appears that on my dev machine the download works fine and streams
the excel file to be saved locally, but on the test server it's streaming
both the page and the Excel file for downloading. I've included the basics of
the code below and was wondering if anyone has a way to explain this
behaviour and how to fix it...

private void Page_Load(object sender, System.EventArgs e)
if( Request.QueryString["filetype"] != null )
// A file download has been requested
string downloadType =
if( downloadType ==
FRSessionParameterName.DownloadSRPTemplate.ToUpper () )
string filePath =
ConfigurationSettings.AppSettings["templatesDir"] +
"/" +
ConfigurationSettings.AppSettings["stormReturnPeriodsDir"] +
"/" +

filePath = this.MapPath( filePath );
DownloadFile( filePath, true );
// Unknown file type - shouldn't happen

private void DownloadFile( string path, bool forceDownload )
string name = Path.GetFileName( path );
string ext = Path.GetExtension( path );
string type = "";

// set known types based on file extension
if ( ext != null )
switch( ext.ToLower() )
case ".htm":
case ".html":
type = "text/HTML";
case ".doc":
case ".rtf":
type = "Application/msword";
case ".xls":
type = "Application/vnd.ms-excel";
type = "text/plain";
if ( forceDownload )
Response.AppendHeader( "content-disposition", "attachment;
filename=" + name );

if ( type != "" )
Response.ContentType = type;

// Force file to download

Nov 19 '05 #1
0 1572

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Mel | last post: by
35 posts views Thread by keerthyragavendran | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.