Reputation: 2560
I am working on an ASP.net project and I have a file upload control. I have a folder in my solution called user_uploads. How can I modify the following code in order to save the files in user_uploads when I publish the solution?
string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs("C:\\temp\\" + fn);
Upvotes: 0
Views: 3851
Reputation: 176896
you just need to do as below get the path of the folder using MapPath and than use that path to save you file ...
string path = HttpContext.Current.ApplicationInstance.Server.MapPath("~/user_uploads");
string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(System.IO.Path.Combine(path, fn));
//FileUpload1.PostedFile.SaveAs(path + fn);
Upvotes: 2