Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, August 5, 2014 5:06 PM
Windows 8. Visual Studio for web 2013. Trying to make a web page that stores a small amount of data in a text file. StreamReader can never find the file. Exception says:
Could not find file 'C:\Users\Tom\Documents\Visual Studio 2013\WebSites\WebSite2\FeatureList.txt'.
Sounds to me like the file isn't there, but if I paste that path into windows explorer, notepad launches and shows me the contents of the file. I've found a number of ways not to find this file:
StreamReader sr = File.OpenText(Server.MapPath("~") + @"data\FeatureList.txt");
//StreamReader sr = new StreamReader(Path.Combine(Server.MapPath("~"), @"data/FeatureList.txt"));
//string path = (string.Format("{0}", AppDomain.CurrentDomain.BaseDirectory,@"\data\FeatureList.txt"));
//StreamReader sr = new StreamReader(path);
//StreamReader sr = new StreamReader(Server.MapPath("~data/FeatureList.txt"));
String FileText = sr.ReadToEnd().ToString();
sr.Close();
Perhaps it's a permission error? If I look at the permissions for the data folder, I see 3 users, SYSTEM, me and Administrator, and not the Default App Pool or IIS users mentioned in "Deploying an ASP.NET website" article I found at asp.net.
I wrote a similar web page a couple years ago that reads but doesn't write and it runs to this day at godaddy.
All replies (3)
Tuesday, August 5, 2014 5:19 PM ✅Answered
StreamReader sr = File.OpenText(Server.MapPath("~/data/FeatureList.txt"));
Assuming your file in located in the data folder inside your root website.
Tuesday, August 5, 2014 10:13 PM ✅Answered
StreamReader sr = File.OpenText(Path.Combine(Server.MapPath("~/data"),"FeatureList.txt"));
Try run VS2013 as administrator
Tuesday, August 5, 2014 5:13 PM
Add "Everyone" to the list of users on the WebSite2 folder and give it full control.