ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Upload multiple file using Multiple FileUpload control and Handler in ASP.Net<p>Hi <a class="username" rel="SajidHussa"> SajidHussa</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; function updateFile() { var formData = new FormData(); for (var i = 0; i &lt; $(&#34;.File&#34;).length; i++) { formData.append($(&#34;.File&#34;)[i].files[0].name, $(&#34;.File&#34;)[i].files[0]); } $.ajax({ url: &#39;Handler.ashx&#39;, type: &#39;POST&#39;, data: formData, cache: false, contentType: false, processData: false, success: function (result) { alert(result.name + &#34; Has been Uploaded SucessFully...&#34;); }, error: function (r) { alert(r.d); } }); } &lt;/script&gt; &lt;div&gt; &lt;input type=&#34;file&#34; id=&#34;fuUpload1&#34; class=&#34;File&#34; /&gt; &lt;br /&gt; &lt;input type=&#34;file&#34; id=&#34;fuUpload2&#34; class=&#34;File&#34; /&gt; &lt;br /&gt; &lt;input type=&#34;button&#34; value=&#34;Upload&#34; onclick=&#34;updateFile()&#34; /&gt; &lt;br /&gt; &lt;/div&gt;</pre> <p><strong><span style="text-decoration: underline;">Handler</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">&lt;%@ WebHandler Language=&#34;C#&#34; Class=&#34;Handler&#34; %&gt; using System; using System.Web; using System.IO; using System.Collections.Generic; public class Handler : IHttpHandler { public void ProcessRequest(HttpContext context) { List&lt;string&gt; names = new List&lt;string&gt;(); for (int i = 0; i &lt; context.Request.Files.Count; i++) { HttpPostedFile postedFile = context.Request.Files[i]; string fileName = Path.GetFileName(postedFile.FileName); if (File.Exists(context.Server.MapPath(&#34;~/images/&#34;) + fileName)) { File.Delete(context.Server.MapPath(&#34;~/images/&#34; + fileName)); } Stream strm = postedFile.InputStream; using (var image = System.Drawing.Image.FromStream(strm)) { int newWidth = 350; int newHeight = 350; var thumbImg = new System.Drawing.Bitmap(newWidth, newHeight); var thumbGraph = System.Drawing.Graphics.FromImage(thumbImg); thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; thumbGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; var imgRectangle = new System.Drawing.Rectangle(0, 0, newWidth, newHeight); thumbGraph.DrawImage(image, imgRectangle); string targetPath = context.Server.MapPath(@&#34;~/images/&#34;) + fileName; thumbImg.Save(targetPath, image.RawFormat); } names.Add(fileName); } //Send File details in a JSON Response. string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(new { name = names }); context.Response.StatusCode = (int)System.Net.HttpStatusCode.OK; context.Response.ContentType = &#34;text/json&#34;; context.Response.Write(json); } public bool IsReusable { get { return false; } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">&lt;%@ WebHandler Language=&#34;VB&#34; Class=&#34;Handler&#34; %&gt; Imports System Imports System.Web Imports System.IO Public Class Handler : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim names As List(Of String) = New List(Of String)() For i As Integer = 0 To context.Request.Files.Count - 1 Dim postedFile As HttpPostedFile = context.Request.Files(i) Dim fileName As String = Path.GetFileName(postedFile.FileName) If File.Exists(context.Server.MapPath(&#34;~/images/&#34;) &amp; fileName) Then File.Delete(context.Server.MapPath(&#34;~/images/&#34; &amp; fileName)) End If Dim strm As Stream = postedFile.InputStream Using image = System.Drawing.Image.FromStream(strm) Dim newWidth As Integer = 350 Dim newHeight As Integer = 350 Dim thumbImg = New System.Drawing.Bitmap(newWidth, newHeight) Dim thumbGraph = System.Drawing.Graphics.FromImage(thumbImg) thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality thumbGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic Dim imgRectangle = New System.Drawing.Rectangle(0, 0, newWidth, newHeight) thumbGraph.DrawImage(image, imgRectangle) Dim targetPath As String = context.Server.MapPath(&#34;~/images/&#34;) &amp; fileName thumbImg.Save(targetPath, image.RawFormat) End Using names.Add(fileName) Next Dim json As String = New System.Web.Script.Serialization.JavaScriptSerializer().Serialize(New With {Key .name = names}) context.Response.StatusCode = CInt(System.Net.HttpStatusCode.OK) context.Response.ContentType = &#34;text/json&#34; context.Response.Write(json) End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/bHDVuS9.gif" alt="" width="470" height="250" /></p>https://www.aspforums.net:443/Threads/112949/Upload-multiple-file-using-Multiple-FileUpload-control-and-Handler-in-ASPNet/https://www.aspforums.net:443/Threads/112949/Upload-multiple-file-using-Multiple-FileUpload-control-and-Handler-in-ASPNet/Wed, 17 Jul 2019 08:16:13 GMT