Re: ajax uploader in ASP.net MVC

  •  01-22-2013, 1:04 PM

    Re: ajax uploader in ASP.net MVC

    Hi amchiche,

     

    You can achieve it in the controllder directly. For example, in the selecting_multiole_files example.

     

    The red part will fire after uploaded. you can save/move/delete/change name in it. 

     

                public ActionResult selecting_multiple_files(string myuploader)
                {
                      using (CuteWebUI.MvcUploader uploader = new CuteWebUI.MvcUploader(System.Web.HttpContext.Current))
                      {
                            uploader.UploadUrl = Response.ApplyAppPathModifier("~/UploadHandler.ashx");
                            //the data of the uploader will render as <input type='hidden' name='myuploader'> 
                            uploader.Name = "myuploader";
                            uploader.AllowedFileExtensions = "*.jpg,*.gif,*.png,*.bmp,*.zip,*.rar";
                            //allow select multiple files
                            uploader.MultipleFilesUpload = true;
                            //tell uploader attach a button
                            uploader.InsertButtonID = "uploadbutton";
                            //prepair html code for the view
                            ViewData["uploaderhtml"] = uploader.Render();
                            //if it's HTTP POST:
                            if (!string.IsNullOrEmpty(myuploader))
                            {
                                  List<string> processedfiles = new List<string>();
                                  //for multiple files , the value is string : guid/guid/guid 
                                  foreach (string strguid in myuploader.Split('/'))
                                  {
                                        Guid fileguid = new Guid(strguid);
                                        CuteWebUI.MvcUploadFile file = uploader.GetUploadedFile(fileguid);
                                        if (file != null)
                                        {
                                              //you should validate it here:
                                              //now the file is in temporary directory, you need move it to target location
                                              //file.MoveTo("~/myfolder/" + file.FileName);
                                              processedfiles.Add(file.FileName);
                                        }
                                  }
                                  if (processedfiles.Count > 0)
                                  {
                                        ViewData["UploadedMessage"] = string.Join(",", processedfiles.ToArray()) + " have been processed.";
                                  }
                            }
                      }
                      return View();
                }

     

    Regards,

     

    Ken 

View Complete Thread