Hey guys,
I would like to read the contents of a file that resides the same directory as my .aspx file. In my C# codebehind, I don't seem to be able to get the correct path. I have tried numerous methods like using "./branch.txt", "branch.txt", "/branch.txt" and even tried using HttpContext.Current.Request.Url.AbsolutePath. etc etc.
Can anyone give me any tips on how to do this please?
I have the folowing code at the moment...
String url = HttpContext.Current.Request.Url.AbsolutePath;
error.InnerHtml += url;
try {
StreamReader sr = new StreamReader("~/branch.txt");
BRANCHID = sr.ReadToEnd();
sr.Close();
}
catch (Exception ex) {
error.InnerHtml += "----------Branch Parsing Exception----------<br>" + ex.Message;
BRANCHID = "17";
}
Please note that "error" is just a placeholder div where I am outputting my results to test.
Cheers.