Save (Insert) multiple files in Folder (Directory) and path in Database using AjaxFileUpload control in ASP.Net

Last Reply 8 months ago By dharmendr

Posted 8 months ago

Using an ASP.NET FileUpload control, I can upload files to a folder and insert their path into a SQL Server database table.

Can someone please tell me how to do the same using Ajax Control Toolkit v 19.1 AjaxFileUpload control?

Actually what I don't understand is how to replace FileUpload1 in foreach loop with Ajax Fileupload or how to proceed from there with Ajax FileUpload control.

C# code which I am using in a button click event to insert record in relational database tables is as follows. I will be very thankful for your time and consideration.

foreach (HttpPostedFile fp in FileUpload1.PostedFiles)
{
    try
    {
        if (fp.ContentLength > 0)
        {
            fp.SaveAs(Server.MapPath("~/Media/") + Path.GetFileName(fp.FileName));
            string MediaLink = "Media/" + Path.GetFileName(fp.FileName);
            string MediaName = Path.GetFileName(fp.FileName);
            string MediaExtension = Path.GetExtension(MediaName);

            if (MediaExtension.ToLower() == ".jpg" || MediaExtension.ToLower() == ".jpeg" || MediaExtension.ToLower() == ".png")
            {
                MediaLink = "<img src=" + MediaLink + " width=460 />";
            }
            else if (MediaExtension.ToLower() == ".wmv" || MediaExtension.ToLower() == ".mp4" || MediaExtension.ToLower() == ".mpg" || MediaExtension.ToLower() == ".avi")
            {
                MediaLink = "<Video width=400 Controls><Source src=" + MediaLink + " type=video/mp4></video>";
            }

            Media.Rows.Add(TextBox1.Text, TextBox10.Text, MediaName, MediaLink);

            Label13.Visible = true;
            Label13.Text = "Upload(s) Successful.";
        }
    }
    catch (Exception)
    {
        Label13.Visible = true;
        Label13.Text = "Upload(s) Failed.";
    }
}

 

Posted 8 months ago