0

After I uploaded file using file uplaod control, and assigning it's name in controller, i need to get that file name in view. Also with that file name how to delete that file in my local drive(which is previously uploaded).

thanks.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

yeah, thanks for that , it works fine . But If i call the above SaveFile, through ajax from my view like $.ajax({ type:"POST", url:"/SaveFile"}); I'm getting httppostfilebase null. can anyone have solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.