473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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...

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

ConfigurationSettings.AppSettings["stormReturnPeriodsTemplate"];
filePath = this.MapPath( filePath );
DownloadFile( filePath, true );
}
else
{
// 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";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
case ".xls":
type = "Application/vnd.ms-excel";
break;
default:
type = "text/plain";
break;
}
}
if ( forceDownload )
{
Response.AppendHeader( "content-disposition", "attachment;
filename=" + name );
}

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

// Force file to download
Response.WriteFile(path);
Response.End();
}
</code>

Nov 19 '05 #1
0 1715

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Mel | last post by:
when downloading files from my site, when file types are known (i.e *.doc) browsers open the file for viewing. is there a way to disable that and just present the save as dialog (same as for...
4
by: Søren Reinke | last post by:
Hi there I am having a little problem. At the company i work in, we are working on a bunch of applications for a server, and also webservices and aspx pages. The main problem is i would...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
2
by: OliviuG | last post by:
I have export to xls functionality in asp.net web form, implemented like this: Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=InvChangeHistory.xls");...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
by: clintonG | last post by:
To all Microsoft partners and customers who have been unable to download recently or access ASP.NET documentation from the msdn2 website and for all of those customers who have been lied to and...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.