Home > Products >DEXTUpload.NET Professional > Code Sample  
 
 
 
 File Upload Default uploaded file
    1. Simple File Upload
    2. Multiple File Upload
    3. Concurrent Upload with other form elements
    4. Upload including multi selected Form element
    5. Obtaining information from uploaded files
    6. Obtaining the width and height information of image file (GIF/JPG/BMP)
    7. Upload into Database BLOB field
    8. Various Save Methods
    9. Checking the existence of file and deleting uploaded file

 Applying File Upload
    1. Save as Single File name
    2. Limiting Upload file capacity
    3. Setting the Upload Timeout
    4. Limiting Upload file type
    5. Canceling upload process with out saving file

 Using Progress Indicator of Server Upload

 File Download
    1. File Download
    2. Database BLOB data Download
File Upload Default
1. Simple File Upload
Page (SimpleUpload.aspx) having the Form to be transmitted is made as the following form.

[SimpleUpload.aspx]
<%@ Page ... %>
<HTML>
<BODY>
<FORM NAME= "writeform" METHOD= "post"ACTION="SU_Process.aspx?ProgressID=0"
ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="file1"><BR>
<INPUT TYPE="submit" VALUE="upload">
</FORM>
</BODY>
</HTML>


In order to transmit Form including file data<input type= "file" ID="File1" NAME="File1">,
ENCTYPE="multipart/form-data" designated in Form tag can not be omitted. The following.
(SimpleUpload.aspx) is the page that proceeds file upload.

[SU_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
fileUpload.Save();
// fileUpload["file1"].Save(); <-- same paragraph
// fileUpload["file1"][0].Save(); <-- same paragraph
}
}


IF you want to change the default path according to the code above, the uploaded file is saved to default path "c:\". You should enter code just like uploadform.DefaultPath = "c:\temp" next to object
generating code uploadform.Save is the method that uploaded files is saved to server as a form of disk file,
it is identical to uploadform("file1") .Save.
In this case, "file 1"should be the same with the name corresponding to NAME property in
<INPUT TYPE="file" NAME="file1" ID="File1">. For more detailed explanation for Save function,
see following below "various Save Methods"

※ Like "Multiple Upload" example, in case when there are several <INPUT TYPE= "file"... ID="File1"
NAME="File1">sections, Expressions such as uloadform.Save, uploadform.SaveAs, uploadform.SaveVirtual,
uploadform.SaveAsVirtual, uploadform.SaveAsBlob, uploadform.FileLen, uploadform.FileName,
uploadform.FilePath, uploadform.MimeType are identical to uploadform("file1").xxx. among several
<INPUT TYPE= "file"... ID= "File2" NAME= "File2">sections, it shows the first file section.
 
2. Multiple File Upload
The following example shows the multiple files upload concurrently

[MultipleUpload.aspx]
<%@ Page ... %>
<HTML>
<BODY>
<FORM NAME= "writeform" METHOD= "post"ACTION="MU_Process.aspx?ProgressID=0"
ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="file1"><BR>
<INPUT TYPE="file" NAME="file2"><BR>
<INPUT TYPE="file" NAME="file3"><BR>
<INPUT TYPE="submit" VALUE="upload">
</FORM>
</BODY>
</HTML>

[MU_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
fileUpload[“file1”].Save();
fileUpload[“file2”].Save();
fileUpload[“file3”].Save();
}
}


The reference to uploaded files is made by the value of property such as NAME( "file1", "file2", "file3").
With another method, they can be saved at a time by using the following repetition after designating
NAME property of various INPUT item as a same value. The following is an example that shows this.

[MultipleUpload2.aspx]
<%@ Page ... %>
<HTML>
<BODY>
<FORM NAME= "writeform" METHOD= "post"ACTION="MU_Process.aspx?ProgressID=0"
ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="files"><BR>
<INPUT TYPE="file" NAME="files"><BR>
<INPUT TYPE="file" NAME="files"><BR>
<INPUT TYPE="submit" VALUE="upload">
</FORM>
</BODY>
</HTML>

[MU_Process2.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
for (int i = 0; i < fileUpload["files"].Count; i++)
fileUpload["files"][i].Save();
}
}


The reference to uploaded files is made by the value of property such as NAME( "file1", "file2", "file3").
With another method, they can be saved at a time by using the following repetition after designating
NAME property of various INPUT items as a same value. The following is an example that shows this

In the example above, you may same result if the form is written by following .

foreach (DEXTUpload.NET.FormElement member in fileUpload["files"])
member.Save();
 
3. Concurrent Upload with other form elements
Like file element, the other elements of Form can be referred by the value of NAME property.

[UploadElements.aspx]
<%@ Page ... %>
<HTML>
<BODY>
<FORM NAME= "writeform" METHOD= "post"ACTION="UE_Process.aspx?ProgressID=0"
ENCTYPE="multipart/form-data">
<INPUT TYPE="text" NAME="title"><BR>
<TEXTAREA NAME="content" ROWS="10" COLS="50"></TEXTAREA><BR>
<INPUT TYPE="file" NAME="file1"><BR>
<INPUT TYPE="submit" VALUE="upload">
</FORM>
</BODY>
</HTML>

[UE_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
string title = fileUpload[“title”].Value;
string content = fileUpload[“content”].Value;
fileUpload[“file1”].Save();
}
}
 
4. Upload including multi selected Form element
In case of handling Multi select Form element that may have multiple values for one Name properties such
as ListBox, Radio button, DEXTUpload can handle this conveniently as the case of Request.Form

[UploadMultiElements.aspx]
<%@ Page ... %>
<HTML>
<BODY>
<FORM NAME= "writeform" METHOD= "post"ACTION="UE_Process.asp?ProgressID=0"
ENCTYPE="multipart/form-data">
<H2>Select your favorite sports</H2>
<SELECT NAME="Sports" MULTIPLE>
<OPTION VALUE="Soccer">Soccer</OPTION>
<OPTION VALUE="Baseball">Baseball</OPTION>
<OPTION VALUE="basketball">Basketball</OPTION>
</SELECT><BR>
<INPUT TYPE="file" NAME="DescFile"><BR>
<INPUT TYPE="submit" VALUE="upload">
</FORM>
</BODY>
</HTML>

[UME_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
Response.Write(“Your favorite sports :<br>");
for (int i = 0; i < fileUpload["Sports"].Count; i++)
Response.Write("-" + fileUpload["Sports"][i].Value + "<br>");
fileUpload["DescFile"].Save();
}
}


In the example above, you may same result if the form is written by following .

foreach (DEXTUpload.NET.FormElement member in fileUpload["Sports "])
Response.Write("-" + member.Value + "<br>")
 
5. Obtaining information from uploaded files
In order to obtain the file information, the following properties are provided.
.FileLen : Length of uploaded file
.FileName : Name of uploaded file(excluding path)
.FilePath : Total path of uploaded file
.MimeType : Mime Type of uploaded file
.LastSavedFileName : File name uploaded and saved in server(excluding path)
.LastSavedFilePath : Total path of file uploaded and saved in server

※ .FileName and .FilePath have a name and a value of total path for uploaded original file.
    The total path value of file uploaded and saved in server can be obtained by using return value
    such as.Save, .SaveAs Method .

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
Response.Write("[Uploaded File Information] <BR>");
Response.Write("FileName : " + fileUpload["file1"].FileName + "<BR>");
Response.Write("FileExtension : " + fileUpload["file1"].FileExtension + "<BR>");
Response.Write("FullPath : " + fileUpload["file1"].FilePath + "<BR>");
Response.Write("FileLength : " + fileUpload["file1"].FileLength + " Byte(s)<BR>");
Response.Write("MimeType : " + fileUpload["file1"].MimeType + "<BR>");

string uploadedPath = fileUpload["file1"].Save();
Response.Write("UploadedPath : " + uploadedPath + "<BR>");
Response.Write("LastSavedFilePath : " + fileUpload["file1"].LastSavedFilePath + "<BR>");
Response.Write("LastSavedFileName : " + fileUpload["file1"].LastSavedFileName);
}
}


The result that the above page is executed will be shown as followings.

[Uploaded File Information]
FileName : sample.jpg
FullPath : c:\data\sample.jpg
FileLength : 176816 Byte(s)
MimeType : image/pjpeg
UploadedPath : d:\upload\sample.jpg
LastSavedFilePath : d:\upload\sample.jpg
LastSavedFileName : sample.jpg
 
6. Obtaining the width and height information of image file (GIF/JPG/BMP)
In case when the uploaded file is an image file(GIF/JPG/BMP), the additional property will be provided to
obtain the width and height of image file as followings

.ImageFormat : Format of uploaded image file
.ImageWidth  : Width of uploaded image file
.ImageHeight : Height of uploaded file

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
Response.Write("[Uploaded Image File Information] <BR>");
Response.Write("FileName : " + fileUpload[“file1”].FileName + "<BR>");
Response.Write("FullPath : " + fileUpload[“file1”].FilePath + "<BR>");
Response.Write("FileLength : " + fileUpload[“file1”].FileLength + " Byte(s)<BR>");
Response.Write("MimeType : " + fileUpload[“file1”].MimeType + "<BR>");
Response.Write("ImageFormat : " + fileUpload[“file1”].ImageFormat + "<BR>");
Response.Write("ImageWidth : " + fileUpload[“file1”].ImageWidth + "<BR>");
Response.Write("ImageHeight : " + fileUpload[“file1”].ImageHeight + "<BR>");

string uploadedPath = fileUpload[“file1”].Save();
Response.Write("UploadedPath : " + uploadedPath);
}
}


The result that the above page is executed will be shown as followings.

[Uploaded File Information]
FileName : sample.jpg
FullPath : c:\data\sample.jpg
FileLength : 176816 Byte(s)
MimeType : image/pjpeg
ImageFormat : JPG
ImageWidth : 1024
ImageHeight : 768

UploadedPath : c:\temp\sample.jpg
 
7. Upload into Database BLOB field
If SaveAsBlob Method is used as followings, the file can be uploaded and saved into Database BLOB field.

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
string ConnectionString = "…”;
OleDbConnection cn = new OleDbConnection(ConnectionString);
cn.Open();

string strQuery = "SELECT filename, filesize, filedata FROM DEXTUPLOAD";
OleDbDataAdapter adapter = new OleDbDataAdapter(strQuery, cn);
adapter.InsertCommand = new OleDbCommand("INSERT INTO DEXTUPLOAD(filedata,
filename, filesize) VALUES (?, ?, ?)", cn);
adapter.InsertCommand.Parameters.Add(…);
adapter.InsertCommand.Parameters.Add(…);
adapter.InsertCommand.Parameters.Add(…);
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataSet ds = new DataSet();
adapter.Fill(ds);

DataRow newRow = ds.Tables[0].NewRow();

using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
newRow[0] = fileUpload.FileName;
newRow[1] = fileUpload.FileLength;
newRow[2] = fileUpload.SaveAsBlob();

ds.Tables[0].Rows.Add(newRow);
adapter.Update(ds);
}
cn.Close();
}
 
8. Various Save Methods
DEXTUpload component provides various save methods that saves the uploaded file into server file system or database. 

* Method that saves a file as a same name of uploaded file into server
- Save : save as DefaultPath property value at the designated path
- Save [Path designation] : save at the designated path
- SaveVirtual [Virtual Path designation] : save at the designated virtual path

* Method that saves a file as an other name of uploaded file into server
- SaveAs [Full Path designation] : saves at the designated path and file name
- SaveAsVirtual [Full Virtual Path designation] : saves at the designated virtual path and file name

* The function that saves uploaded file into Database BLOB field
- SaveAsBlob [ADO Field object designation] : saves at the designated Database BLOB field

※ All Save Methods except SaveAsBlob has an element called bOverwrite and the total path for file saved
in the server as a return value. In case when bOverwrite element is omitted, default is True, in case when there is a same file name in the related path, it is overwritten . In case when the element value of
bOverwrite is set as False, the single file name is saved ( filename(2).ext, filename(3).ext ... ).
 
9. Checking the existence of file and deleting uploaded file
DEXTUpload provides FileExist method that can check the existence of file and DeleteFile method can
delete uploaded file. The following is the example that the uploaded file is saved by using FileExists and
SaveAs method.

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
string filename = fileUpload[“file1”].Filename;
string filepath = fileUpload[“file1”].DefaultPath + "\\" + filename;

// path value to file name(excluding extension)
if (fileUpload[“file1”].FileExists(filepath))
{
string filenameonly;
string fileext;

int Index = filepath.LastIndexOf(".");
if (Index > 0)
{
// In case when there exists extension
filenameonly = filepath.Substring(0, Index); // path value to file name(excluding extension)
fileext = filepath.Substring(Index); // "."extension with character
}
else
{
// In case when there is no extension
filenameonly = filepath;
fileext = "";
}

// Obtaining single file path
for (int i=2; ; i++)
{
filepath = filenameonly + "(" + i.ToString() + ")" + fileext;
if (!File.Exists(filepath)) break;
}
}

fileUpload["file1"].SaveAs(filepath);

// If necessary, this file may be deleted .
// fileUpload.DeleteFile(filepath);
}
}


※ DEXTUpload.NET provides the function that saves file as a single name basically .
The example above is not the method provided by DEXTUpload.NET, but the case when single file name is decided in user’s own way
Applying File Upload
1. Save as Single File name
Save, SaveVirtual, SaveAs, SaveAsVirtual Method is overwritten in case when uploaded file is saved basically if there is a same file name in the related path. If you want to save the file as a single name without
overwriting, the second element, bOverwrite should be set as False.
(see "Various Save Methodss" Chapter)

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
string UploadedFilename = fileUpload[“file1”].SaveAs(“C:\\Data\\sample.zip”, false);
Response.Write(“uploaded file : “ + UploadedFilename);
}
}


In the example above, there exists sample zip file in c:\data folder, the uploaded file is saved as the name of "c:\data\sample(2).zip", the page is shown as following.

[ Execution Result ]
uploaded file : c:\data\sample(2).zip
 
2. Limiting Upload file capacity
If you use MaxFileLen property, the maximum file size can be limited. In case of uploading bigger file than the designated size, the following error may be occured.

DEXTUpload error '80040200'
Warning: File size must be less than 5242880 Bytes.
/form_process.asp, line 27


Like following example, the maximum file size is not exceeded by using FileLen property, and calling Save Method The limitation to the upload file size may be customized without occurring error.

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
fileUpload.MaxFileLength = 5242880;

if (fileUpload["file1"].FileLength > fileUpload.MaxFileLength)
{
Response.Write("File size must be less than 5MBytes.<br>");
Response.Write("Press the back button on your browser...<br>");
}
else
{
fileUpload["file1"].Save();
}
}
}
 
3. Setting the Upload Timeout
Since the working process such as file upload or Save takes a long time in case of uploading mass storage file if the value of Server.ScriptTimeout(Default: 90sec) and Session.Timeout(Default: 20min) is not changed, upload process is not executed due to Timeout error.

By providing UploadTimeout property, DEXTUpload can upload mass storage file without Timeout error. You don’t have to set Session Timeout of Server.ScriptTimeout,
The default value is 3600sec(60min) and may be used by modifying value according to the necessity .

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
fileUpload.UploadTimeout = 1800;
fileUpload[“file1”].Save();
}
}


In the example above, since the value of UploadTimeout is set as 1800sec(30min), Time error may not occurred if Save process is not exceeded 1800sec.
 
4. Limiting Upload file type
By using Mime Type property provided by DEXTUpload, the uploadable file type can be limited.
the following type example can be uploaded by using GIF and JPG file only.

[Form_Process.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
string mimetype = fileUpload["file1"].MimeType
if (mimetype=="image/gif" || mimetype=="image/pjpeg")
fileUpload["file1"].Save();
else
Response.Write("Your file must be GIF or JPG...<br>");
}
}
 
5. Canceling upload process with out saving file
By using Flush method provided by DEXTUpload, you can cancel upload progress and execute the remained code continuously without saving file into server if necessary .
The following is the example that shows error message by canceling upload in case when upload file
capacity is exceeded during file uploading.

[Form_Proc.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
if (Request.TotalBytes > 1048576)
{
fileUpload.Flush();
Response.Write("Warning: File size must be less than 1 MBytes.");
}
else
{
fileUpload.Save();
Response.Write("File-upload completed.");
}
}
}
Using Progress Indicator of Server Upload
1. Using Progress Indicator of Server Upload
By using Server-side Graphical Progress Indicator, you can see the file upload progress and monitor upload
speed, total contents size and the present uploaded contents size, the remained time, present progress
information without downloading additional Client Side softwares such as ActiveX Control or Java Applet.

[ Form preparation page (GPIUpload.aspx) ]
<%@ Page … %>
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function ShowProgress()
{
strAppVersion = navigator.appVersion;

if (document.write_form.file1.value != "")
{
ProgressID = (new Date()).getTime() % 1000000;
if (ProgressID==0) ProgressID = 1000000;

if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4) {
winstyle = "dialogWidth=385px; dialogHeight:150px; center:yes";
window.showModelessDialog("../Progress/show_progress_IE.aspx?ProgressID="+ProgressID,
null, winstyle);
}
else
{
winpos = "left=" + ((window.screen.width-380)/2) +",top="+((window.screen.height-110)/2);
winstyle="width=380,height=110,status=no,toolbar=no,menubar=no,location=no,resizable=no,
scrollbars=no,copyhistory=no," + winpos;
window.open("../Progress/show_progress_NN.aspx?ProgressID="+ProgressID,null,winstyle);
}

document.write_form.action = " form_process.aspx?ProgressID=" + ProgressID;
}
return true;
}
//-->
</SCRIPT>
</HEAD>

<BODY>
<FORM NAME= "writeform" METHOD= "post"ACTION="form_process.aspx?ProgressID=0"
ENCTYPE="multipart/form-data" onSubmit="return ShowProgress();">

<INPUT TYPE="file" NAME="file1"><BR>
<INPUT TYPE="submit" VALUE="upload">
</FORM>
</BODY>
</HTML>


In order to use Progress Indicator, you should add Java script such as ShowProgress() like
the example above. And in order to show Progress Indicator by calling ShowProgress() function
before submitting form, the new window(or dilaog box) is occurred .
At this time, the page shown in the new window is as following .

[ Page that shows Progress Indicator for Internet Explorer (show_progress_IE.aspx)  ]
<%@ Page EnableSessionState="false" … %>
<html>
<head>
<title>Uploading Files...</title>
<STYLE type="text/css">
td {font-size: 9pt}
</STYLE>
</head>
<body MS_POSITIONING="GridLayout" bgcolor=#d4d0c8 leftmargin=8 topmargin=0 scroll= no><BR><IFRAMEsrc="show_prog_body.aspx?ProgressID=<%Response.Write(Request.QueryString["ProgressID"]);%>"
title="Progress Step1" frameborder=0 marginheight=0 marginwidth=0 noresize scrolling=no
width=365 height=65>
</IFRAME>
<br><br>

<table border=0 width=365 cellpadding=2 cellspacing=0 bgcolor=#d4d0c8>
<tr><td>Click the <b>STOP</b> button on your browser to abort uploading.</td></tr>
</table>

</body>
</html>

[ page that shows Progress Indicator for Netscape Navigator (show_progress_NN.aspx)]
<%@ Page EnableSessionState="false" … %>
<frameset rows="80,1*" border="0" framespacing="0" frameborder= "NO"><BR><framesrc="show_prog_body.aspx?ProgressID=<%Response.Write(Request.QueryString["ProgressID"]);%>"

noresize scrolling="NO" frameborder="NO" name="sp_body">
<frame src="show_prog_bottom.aspx" noresize scrolling="NO" frameborder="NO" name="sp_bottom">
</frameset>


In order to show Progress Indicator, in addition to“show_progress.asp” above, the next “show_prog_body.asp”
and “show_prog_bottom.asp” are needed
1) show_progress.asp: Progress Indicator in oder to show it , web page should be divided by frame.
2) show_prog_body.asp: really shows Progress Indicator.
3) show_prog_bottom.asp: ( Like Netscape Navigator, the browser that does not support Inline Frame, is needed)

[ page that shows Progress Indicator (show_prog_body.aspx) ]
<%@ Page EnableSessionState="false" … %>

[ page that shows Progress Indicator (show_prog_body.aspx.cs) ]
private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUploadMonitor monitor = new DEXTUpload.NET.FileUploadMonitor())
{
monitor.ShowMonitor();
}
}

[ page that shows Progress Indicator (show_prog_bottom.aspx)]
<%@ Page EnableSessionState="false" … %>
<HTML>
<HEAD>
<title>show_prog_bottom</title>
<STYLE type="text/css">
td {font-size: 9pt}
</STYLE>
</HEAD>
<body MS_POSITIONING="GridLayout" bgcolor="#d4d0c8" leftmargin="8" topmargin="0" scroll="no">
<table border="0" width="365" cellpadding="0" cellspacing="0" bgcolor="#d4d0c8">
<tr><td>Click the <b>STOP</b> button on your browser to abort uploading.</td></tr>
</table>
</body>
</HTML>


If you see ASP page above, you can check that "EnableSessionState" property is set as False, and session
situation is canceled. If session situation of this page is not canceled, since you can not see the page result executed by the time of completing file upload, that is the submission of Form, be sure to cancel the
session situation of page.. ShowMonitor Method shows upload progress in each time. And in case of
completing upload, window (or dialog box is automatically closed.

[ page that handles upload progress (form_process.aspx.cs) ]

private void Page_Load(object sender, System.EventArgs e)
{
using (DEXTUpload.NET.FileUpload fileUpload = new DEXTUpload.NET.FileUpload())
{
fileUpload[“file1”].Save();
}
}


The page that handles upload progress should be written equally with disregard to use of Progress
Indicator.
File Download
1. File Download
In Download, DownloadVirtual Method of FileDownload object, users can download file in the server from
web browser.
Download : downloads file existed in the designated path of server.
DownloadVirtual : downloads files existed in the designated virtual path of server.

[Download.aspx.cs]

private void Page_Load(object sender, System.EventArgs e)
{
Response.Buffer = false;
string ContentDisposition = "";
string ContentType = "";

if (Request.UserAgent.IndexOf("MSIE") >= 0)
{
//In case of IE 5.0
if (Request.UserAgent.IndexOf("MSIE 5.0") >= 0)
{
ContentDisposition = "inline;filename=";
ContentType = "application/x-msdownload";
}
//In case of not IE 5.0
else
{
ContentDisposition = "inline;filename=";
ContentType = "application/unknown";
}
}
else
{
//In case of other browser such as Netscape etc.
ContentDisposition = "attachment;filename=";
ContentType = "application/unknown";
}

string FileName = Request.QueryString["filename"];
string FilePath = Request.QueryString["filepath"];

using (DEXTUpload.NET.FileDownload fileDownload = new DEXTUpload.NET.FileDownload())
{
Response.AddHeader("Content-Disposition", ContentDisposition + FileName);
System.IO.FileInfo fInfo = new System.IO.FileInfo(FilePath);
Response.AddHeader("Content-Length", fInfo.Length.ToString());
fInfo = null;
Response.ContentType = ContentType;
Response.CacheControl = "public";

fileDownload.Download(FilePath);
}
}


If the ASP page above is executed with the total path of file to be downloaded , the related file can be
donloaded. If you see the upper part of page, you can check that file can be downloaded by designating
as Response.Buffer = False without buffering. Download method is called after designating the head
information such as Content- Disposition, Content-Length, ContentType etc. Users can download file by
designating the file name and path to be downloaded in the dialog box of web browser.
 
2. Database BLOB data Download
In DownloadBlob Method of FileDownload object, you can download database BLOB in the server from web browser to disk file of users. Except the Database-related part, it is identical to Download Method.

[ DownloadBlob.asp ]

private void Page_Load(object sender, System.EventArgs e)
{
Response.Buffer = true;
string ContentDisposition = "";
string ContentType = "";

if (Request.UserAgent.IndexOf("MSIE") >= 0)
{
//In case of IE 5.0
if (Request.UserAgent.IndexOf("MSIE 5.0") >= 0)
{
ContentDisposition = "inline;filename=";
ContentType = "application/x-msdownload";
}
//In case of not IE 5.0
else
{
ContentDisposition = "inline;filename=";
ContentType = "application/unknown";
}
}
else
{
//In case of other browser such as Netscape etc.
ContentDisposition = "attachment;filename=";
ContentType = "application/unknown";
}

string FileID = Request.QueryString["fileid"];

string ConnectionString = "…”;
OleDbConnection cn = new OleDbConnection(ConnectionString);
cn.Open();

string strQuery = "SELECT filename, filesize, filedata FROM DEXTUPLOAD WHERE fileid = " + FileID;
OleDbCommand cmd = new OleDbCommand(strQuery, cn);
OleDbDataReader dataReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

if (dataReader.Read())
{
string FileName = dataReader.GetString(0);
int FileSize = dataReader.GetInt32(1);

using (DEXTUpload.NET.FileDownload fileDownload = new DEXTUpload.NET.FileDownload())
{
Response.AddHeader("Content-Disposition", ContentDisposition + FileName);
Response.AddHeader("Content-Length", FileSize.ToString());
Response.ContentType = ContentType;
Response.CacheControl = "public";

fileDownload.DownloadBlob(dataReader, 2);
}
}
}
 
 
Move to devpia     Address: 5F, Mirae Building, 87-2, Nonhyun-dong, Gangnam-gu, Seoul, Korea Tel: +82-2-6719-6200  Business Registration Number: 220-81-90008
  Copyright ⓒ 2007 DEVPIA, Inc. All rights reserved.