SIGN UP MEMBER LOGIN:    
ARTICLE

Uploading Multiple Files Using Flash in ASP.Net

Posted by Raju Katare Articles | ASP.NET Programming January 19, 2011
In this article you will learn how to Upload Multiple Files Using Flash in ASP.Net
Reader Level:

Add "FlashUpload.dll" to Bin folder of ASP.Net.

Upload.cs class

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public class Upload : IHttpHandler, IRequiresSessionState
{   

    public bool IsReusable
    {
        get { return true; }
    }
    public void ProcessRequest(HttpContext context)
    {
        if ( context.Request.Files.Count > 0 )
        {
            for(int j = 0; j < context.Request.Files.Count; j++)
            {
                HttpPostedFile uploadFile = context.Request.Files[j];
                if (uploadFile.ContentLength > 0)
                {
                    uploadFile.SaveAs(context.Server.MapPath("~/Uploads/"+uploadFile.FileName));                   
                }               
            }
        }
    }

}

Web.config

In  <system.web> of config file add the following tags
    <httpHandlers>
      <!--

        The httpHandler that files are uploaded to, defined in App_Code/Upload.cs
     
-->
      <
remove verb="POST,GET" path="Upload.cs"/>
      <add verb="POST,GET" path="Upload.cs" type="Upload"/>
    </httpHandlers>
    <!--

        The maximum files size allowed
     
-->
    <
httpRuntime maxRequestLength="1550000"/>
    <customErrors mode="Off" />

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>
<%@ Register Assembly="FlashUpload" Namespace="FlashUpload" TagPrefix="FlashUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<
body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="LinkButton1" runat="server"
            Visible="False">LinkButton</asp:LinkButton>
        <br />
    <FlashUpload:FlashUpload ID="flashUpload" runat="server"
            UploadPage="Upload.cs" OnUploadComplete="UploadComplete()"
            FileTypeDescription="Images"
            FileTypes="*.*"
            UploadFileSizeLimit="1800000" TotalUploadSizeLimit="2097152" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string jscript = "function UploadComplete(){" + ClientScript.GetPostBackEventReference(LinkButton1, "") +"};";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "FileCompleteUpload", jscript, true);
        }
    }
}


asp.net.gif

Login to add your contents and source code to this article
share this article :
post comment
 

Hi..I got this error: There has been an I/O Error: Error #2038 when i try to run this on IIS7 can u please suggest me something.

Posted by Nilesh Nov 10, 2011

Its Nice and working what I want to know is what is the use of FlashUpload.dll.What does it contain?If possible can you tell me please.My id id pathak_rajdeep@rediffmail.com.

Posted by Rajdeep Pathak May 31, 2011

Hi raju, nice work.. but sometime i am receiving a script error "Object Expected" when try to click "Upload Files" button. The selected files are uploaded successfully but with this script error.. Please advice.. thx,

Posted by shadi mah Mar 01, 2011

it's working fine for me on all browsers

Posted by Raju Katare Feb 08, 2011

i don't think it's browser error i check it on IE & chrome still generate the same error could u help please?

Posted by muhammad gaber Jan 27, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor