开发者

How to get filename to from controller in asp.net mvc

开发者 https://www.devze.com 2023-02-25 12:03 出处:网络
After I uploaded file using file uplaod control, and assigning it\'s name in controller, i need to get that file name in v开发者_开发技巧iew. Also with that file name how to delete that file in my loc

After I uploaded file using file uplaod control, and assigning it's name in controller, i need to get that file name in v开发者_开发技巧iew. Also with that file name how to delete that file in my local drive(which is previously uploaded).

thanks.


check it please

 public ActionResult SaveFile(HttpPostedFileBase FileUpload)
        {             
                string path = string.Empty;
                if (FileUpload != null)
                    if (FileUpload.ContentLength > 0)
                    {
                        fileName = Path.GetFileName(FileUpload.FileName);
                        path = Path.Combine(Server.MapPath("~/App_Data/Documents"), fileName);
                        FileUpload.SaveAs(path);
                    }                 

                return View();            
        } 

and don't forget to add enctype = "multipart/form-data" attribute to form

to can use this jQuery plugin to upload file via ajax jQuery File Upload in ASP.NET MVC

0

精彩评论

暂无评论...
验证码 换一张
取 消