I am developing a project on ASP.NET C#. I need to reach a folder which is located at "D://Records/" I tried Server.MapPath, but it did not help me.
Server.MapPath("../D/Records/");
How can I reach this location at C# side?
Thank you.
I am developing a project on ASP.NET C#. I need to reach a folder which is located at "D://Records/" I tried Server.MapPath, but it did not help me.
Server.MapPath("../D/Records/");
How can I reach this location at C# side?
Thank you.
You can not access physical drives(like C:
Drive,D:
Drive ) from the client machine. instead of that create a dedicated folder for your files inside your project root folder
and try accessing that.
ProjectRootFolder
|
|
MyFiles (create MyFiles Folder inside your project root folder)
|
|
|--- file1.txt
|--- file2.txt
Try This
String file1Path=Server.MapPath("~/MyFiles/file1.txt");
String file2Path=Server.MapPath("~/MyFiles/file2.txt");
You need to give virtual path instead of physical path
Path
Specifies the relative or virtual path to map to a physical directory. If Path starts with either a forward (/) or backward slash (), the MapPath method returns a path as if Path were a full, virtual path. If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed.
To get the root path of site
Server.MapPath("~")
To get current director path
Server.MapPath(".")
To get the path of the parent directory
Server.MapPath("..")