I. jquery progress bar code:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "UpLoad. aspx. cs" Inherits = "UploadifyDemo_UpLoad" %>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Link href = "js/jquery. Uploadify-v2.1.4/uploadify.css" rel = "stylesheet" type = "text/css"/>
<Script type = "text/javascript" src = "js/jquery. Uploadify-v2.1.4/jquery-1.4.2.min.js"> </script>
<Script type = "text/javascript" src = "js/jquery. Uploadify-v2.1.4/swfobject. js"> </script>
<Script type = "text/javascript" src = "js/jquery. Uploadify-v2.1.4/jquery. uploadify. v2.1.4.min. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
$ ("# Uploadify"). uploadify ({
'Upload': 'JS/jquery. Uploadify-v2.1.4/uploadify.swf ', // path of the uploadify.swf file
'Script': 'uploadhandler. Ashx', // path of the background script for processing file uploads
'Cancelim': 'JS/jquery. Uploadify-v2.1.4/cancel.png ',
'Folder': 'uploadfile/<% = subpathName %> ', // path of the upload folder
'Queueid': 'filequeue ', // id of the element you want to use as a file queue on the page
'Auto': false, // automatic Upload when a file is added to the queue
'Multi ': true, // if it is set to true, multi-file upload is allowed.
'Fileext ':' *. jpg; *. gif; *. png ', // specifies the suffix of the file to be uploaded.
'Filedesc': 'Web Image Files (. JPG,. GIF,. PNG) ', // text displayed in the file type drop-down menu at the bottom of the browser window
'Sizelimmit ': 102400, // size limit of the file to be uploaded, measured in 100 KB
'Oncancel': function (event, ID, fileObj, data) {// triggered once each file is removed from the upload queue
Alert ('The upload of '+ fileObj. name + 'has been canceled! ');
},
'Oncomplete': function (event, ID, fileObj, response, data) {// triggered every time a file is uploaded
Alert ('There are '+ data. fileCount + 'files remaining in the queue .');
},
'Onallcomplete': function (event, data) {// triggered when all files in the upload queue are uploaded
Alert (data. filesUploaded + 'files uploaded successfully! ');
}
});
});
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
</Div>
</Form>
<Div id = "fileQueue"> </div>
<Input type = "file" name = "uploadify" id = "uploadify"/>
<P>
<A href = "javascript: $ ('# uploadify'). uploadifyUpload ()"> Upload </a> |
<A href = "javascript: $ ('# uploadify'). uploadifyClearQueue ()"> cancel Upload </a>
</P>
</Body>
</Html>
2. Back-end program code that generates the jquery progress bar data source:
<% @ WebHandler Language = "C #" Class = "UploadHandler" %>
Using System;
Using System. Web;
Using System. IO;
Public class UploadHandler: IHttpHandler
{
Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
Context. Response. Charset = "UTF-8 ";
HttpPostedFile file = context. Request. Files ["Filedata"];
String uploadPath = HttpContext. Current. Server. MapPath (@ context. Request ["folder"]);
If (file! = Null)
{
If (! Directory. Exists (uploadPath ))
{
Directory. CreateDirectory (uploadPath );
}
File. SaveAs (Path. Combine (uploadPath, file. FileName ));
Context. Response. Write ("1 ");
}
Else
{
Context. Response. Write ("0 ");
}
}
Public bool IsReusable
{
Get
{
Return false;
}
}
}