pointeman
asked on
Local Directory UnauthorizedAccessException?
This is strange, building Win App (root directory) and cannot access sub-directory 'Logs' "UnauthorizedAccessExcepti on"
private static string path = AppDomain.CurrentDomain.Ba seDirector y;
private static string file = path + "Logs";
private void btnRead_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read));
using (sr)
{
string line = "";
while ((line = sr.ReadToEnd()) != null)
{
listBox1.Items.Add(line);
}
}
}
private static string path = AppDomain.CurrentDomain.Ba
private static string file = path + "Logs";
private void btnRead_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read));
using (sr)
{
string line = "";
while ((line = sr.ReadToEnd()) != null)
{
listBox1.Items.Add(line);
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ok I see - I actually created a text file called Logs without a file extension to test - I thought that was what you were doing!
ASKER
Also, the 'Using' statement works much better, thanks...