Introduction
May be some of will say this old staff and there is hundreds of such article but may be there are true but what I did found speak in general not in details how to deal with Unicode files to download from server or multi segment file name problem epically with Firefox browser which cause lot of problems.
Background
During last couple days in I got a web project for one of our departments
that contain download section provided file download for public and site
members but there is was a little problem that they some times upload on site
files in different formats, so there is a little problem with files with such format
like htm, txt for example they open directly inside browser window which bad
idea to have such option on download section. Then I decide to build web user
control to force open save dialog on any browser web site open with, which I
would like to provide some useful info about to you.
And I will try to focus on some problems that I faced during development
of this web user control too.
Using the code
I will expect that ever one can add new user control to there own web project using any Microsoft .NET IDE. after we add this control and name it FileDownload
we will go to code behind page because we will not need for GUI representation for our control.
inside our control we should specify couple of system constants and member variables:
private const string filesFolder = "~/docs/";
I will use hard coded file for easer understand, now after that we will go into Load
event to handle with query string that hold our file id which user wants to download from our web site.
protected void Page_Load(object sender, EventArgs e)
{
filesFolder + FileNameOnServer);
fileSize = stream.Length;
Response.AddHeader("Content-Length", fileSize.ToString());
Response.ContentType = "application/octet-stream";
}
catch {}
finally
{
if ( stream != null )
stream.Close();
}
After we set this code now we can use this control inside any page so we can handle file download on any browser type.