Asp.Net AjaxFileUpload Control With Drag Drop And Progress Bar
This Example explains how to use AjaxFileUpload Control With Drag Drop And Progress Bar Functionality In Asp.Net.
May 2012 release of AjaxControlToolkit includes a new AjaxFileUpload Control which supports Multiple File Upload, Progress Bar and Drag And Drop functionality.
These new features are supported by Google Chrome version 16+, Firefox 8+ , Safari 5+ and Internet explorer 10 + , IE9 or earlier does not support this feature.
To start with it, download and put latest AjaxControlToolkit.dll in Bin folder of application, Place ToolkitScriptManager and AjaxFileUpload on the page.
HTML SOURCE
ThrobberID is used to display loading image instead of progress bar in unsupported browsers.
Type of files uploaded can be restricted by using AllowedFileTypes property with comma separated list such as "zip,doc,pdf".
Write following code in OnUploadComplete event to save the file.
C#
VB.NET
Build and run the code.
May 2012 release of AjaxControlToolkit includes a new AjaxFileUpload Control which supports Multiple File Upload, Progress Bar and Drag And Drop functionality.
These new features are supported by Google Chrome version 16+, Firefox 8+ , Safari 5+ and Internet explorer 10 + , IE9 or earlier does not support this feature.
To start with it, download and put latest AjaxControlToolkit.dll in Bin folder of application, Place ToolkitScriptManager and AjaxFileUpload on the page.
HTML SOURCE
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
OnUploadComplete="UploadComplete"
ThrobberID="loader"/>
<asp:Image ID="loader" runat="server"
ImageUrl ="~/loading.gif" Style="display:None"/>
ThrobberID is used to display loading image instead of progress bar in unsupported browsers.
Type of files uploaded can be restricted by using AllowedFileTypes property with comma separated list such as "zip,doc,pdf".
Write following code in OnUploadComplete event to save the file.
C#
1
protected
void
UploadComplete(
object
sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
2
{
3
string
path = Server.MapPath(
"~/Uploads/"
) + e.FileName;
4
AjaxFileUpload1.SaveAs(path);
5
}
1
protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
2
{
3
string path = Server.MapPath(
"~/Uploads/"
) + e.FileName;
4
AjaxFileUpload1.SaveAs(path);
5
}
This comment has been removed by the author.
ReplyDeleteThe "VB.NET code" is just the C# code copied and pasted again. It should look something like this:
ReplyDeleteProtected Sub UploadComplete (sender as Object, e as AjaxControlToolkit.AjaxFileUploadEventArgs)
Dim path as String = Server.MapPath("~/Uploads/" & e.FileName
AjaxFileUpload1.SaveAs(path)
End Sub
The maximum number of files field isnt working... Can You Please Help.... Thanks in Advance
ReplyDeleteVery fine exsample!!! But why doesn't the code show what is going on! What about the drag'n drop and the progressbar... ...please!! :o)
ReplyDeleteHow do you apply custom styles to the buttons and messages?
ReplyDeleteI can only find following properties to set in css :
.ajax__fileupload_selectFileContainer {position: relative;float: left;right: 0px;}
.ajax__fileupload_dropzone {border:dotted 1px #B2D1E0 !important;color:#B2D1E0 !important;}
Anyone knows the other properties (for the buttons etc.)?
I donwloaded this sample - it runs fine but no upload of the files to the server????
ReplyDeleteGreate sample code ty :)
ReplyDelete