Upload Files Asynchronously With JQuery Uploadify Asp.Net
In this example i'm explaining how to Upload Multiple Files Asynchronously In Gmail Style With Progress bar Using JQuery Uploadify Plugin In Asp.Net C# and VB.
Download Latest JQuery Library And Uploadify Plugin.
Create a folder in application and add swf,css and js files in it from links above.
Open HTML source and add reference to these javascripts in head section.
<link href="Scripts/uploadify.css" rel="stylesheet" type="text/css"/>
<script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"/>
<script src="Scripts/jquery.uploadify-3.1.js" type="text/javascript"/>
<script src="Scripts/jquery.uploadify-3.1.min.js" type="text/javascript"/>
Place one FileUpload Control on the page.
1: <form id="form1" runat="server">
2: <div>
3: <asp:FileUpload ID="FileUpload1" runat="server"/>
4: </div>
5: </form>
Add this JavaScript in Head section.
1: <script type = "text/javascript">
2: $(document).ready(function()
3: {
4: $("#<%=FileUpload1.ClientID %>").uploadify(
5: {
6: 'swf': 'Scripts/uploadify.swf',
7: 'uploader': 'Handler.ashx',
8: 'auto': true,
9: 'multi': true,
10: 'buttonText': 'Select File(s)'
11: });
12: });
13: </script>
Right Click on Solution explorer, Add new Generic Handler and write below mentioned code to save the file.
C# CODE
01<%@ WebHandler Language="C#" Class="Handler" %>02using System;03using System.Web;04 05public class Handler : IHttpHandler {06 07 public void ProcessRequest (HttpContext context) {08 HttpPostedFile fileToUpload = context.Request.Files["Filedata"];09 string pathToSave = HttpContext.Current.Server.MapPath("~/Files/") + fileToUpload.FileName;10 fileToUpload.SaveAs(pathToSave);11 }12 13 public bool IsReusable {14 get {15 return false;16 }17 }18}VB.NET CODE
01Imports System.Web02 03Public Class Handler04 Implements IHttpHandler05 06 Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest07 Dim fileToUpload As HttpPostedFile = context.Request.Files("Filedata")08 Dim pathToSave As String = HttpContext.Current.Server.MapPath("~/Files/") & fileToUpload.FileName09 fileToUpload.SaveAs(pathToSave)10 End Sub11 12 Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable13 Get14 Return False15 End Get16 End Property17End ClassBuild and run the application.
.png)

thank u very much
ReplyDeleteIt doesn't work in IE9 for me, when I click 'Select File(s)' button nothing happens. In other browsers works fine
ReplyDeleteThanks. Nice
ReplyDeletehttp://www.coding-issues.com/2015/11/upload-file-asynchronously-using-jquery.html
Thanks,
ReplyDeletehttp://dotnetawesome.blogspot.com/2014/10/how-to-upload-files-asynchronously-using-aspnet-mvc4-application.html