When you run a web application, the current working directory of the process isn’t the directory containing your source code. You might want to look at HttpServerUtility.MapPath
or HostingEnvironment.MapPath
.
Note that this doesn’t really have anything to do with StreamReader
– for diagnostic purposes, you’d be better off with something like:
FileInfo file = new FileInfo("../Content/items.xml");
Debug.WriteLine(file.FullName);
solved Streamreader Directory [closed]