I want to upload a file in a physical path such as E:\Project\Folders
.
I got the below code by searching in the net.
//check to make sure a file is selected
if (FileUpload1.HasFile)
{
//create the path to save the file to
string fileName = Path.Combine(Server.MapPath("~/Files"), FileUpload1.FileName);
//save the file to our local path
FileUpload1.SaveAs(fileName);
}
But in that, I want to give my physical path as I mentioned above. How to do this?
Server.MapPath("~/Files")
returns an absolute path based on a folder relative to your application. The leading~/
tells ASP.Net to look at the root of your application.To use a folder outside of the application:
Of course, you wouldn't hardcode the path in a production application but this should save the file using the absolute path you described.
With regards to locating the file once you have saved it (per comments):
Well,
you can accomplish this by using the VirtualPathUtility