Upload files with progress bar in ASP.Net MVC

Last Reply on May 22, 2014 03:31 AM By Mudassar

Posted on May 22, 2014 03:31 AM

Hi,

I have the code to file upload but i want to show the status of file uploading using progressbar.How do i do that?

<form action="Fileupload" method="post" enctype="multipart/form-data">

  <label for="file">Filename:</label>
  <input type="file" name="file" id="file" />

  <input type="submit"value="Upload" id="sub"  />

    @if(ViewData.ContainsKey("Message"))
     { 
     <div id="flash-message">@ViewData["Message"]</div>
     } 

</form>

 

 public ActionResult Fileupload(HttpPostedFileBase file)
        {
            if (file != null)
            {
                var fname = Path.GetFileName(file.FileName);
            
                var exis = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Storage/uploads"), fname);
                if (System.IO.File.Exists(exis))
                {
                    ViewData["Message"] = "The file " + fname + " has already exists";
                }
                else
                {
                   try
                   {

                        if (file.ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            fname = fileName;
                            var path = Path.Combine(Server.MapPath("~/Storage/uploads"), fileName);
                            file.SaveAs(path);
                        }
                        ViewData["Message"] = "The file " + fname + " has uploaded successully";
                   }
                   catch (Exception e)
                   {
                        ViewData["Message"] = "The file " + fname + " Could not upload";
                      ViewData["Message"] = e.Message;
                    }
                }
            }
            else
                ViewData["Message"] = "Please choose file";
                return View();
        }

 

Posted on May 22, 2014 03:31 AM

Refer

http://lbrtdotnet.wordpress.com/2011/09/02/asp-net-mvc-multiple-file-uploads-using-uploadify-and-jqueryui-progressbar/

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html