Link to home
Start Free TrialLog in
Avatar of pointeman
pointemanFlag for United States of America

asked on

Local Directory UnauthorizedAccessException?

This is strange, building Win App (root directory) and cannot access sub-directory 'Logs' "UnauthorizedAccessException"

        private static string path = AppDomain.CurrentDomain.BaseDirectory;
        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
Avatar of daveamour
daveamour
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pointeman

ASKER

I discoved it's impossible to open a 'path' as a fle, doh...
Also, the 'Using' statement works much better, thanks...
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!