I have a .NET application that I am trying to debug and part of my application loads a file from my project. This file is located at
C:\Users\USER_FOLDER\Documents\Visual Studio 2012\Projects\MY_PROJECT\_templates\myFile.html
In my code, I specify a relative path to the file and use the DirectoryInfo class to get the full directory path to my file:
string myFile = (new DirectoryInfo("_templates/myFile.html")).FullName;
However, this returns the following path (extra \'s as escape characters):
"C:\\Program Files\\IIS Express\\_templates\\myFile.html"
I was expecting the path that is returned when debugging in IIS Express would match the first path I listed, not the third. Why is this? Is there something else that I need to set up in my project to have it derive the paths properly? I'm assuming that this would not happen if I deployed my code to a IIS7 site, but I haven't gotten to that testing level yet.
Use Server.MapPath:
Server.MapPath("~/_templates/myFile.html")
or HttpServerUtility.MapPath:
HttpServerUtility.MapPath("~/_templates/myFile.html")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With