?
Solved

Local Directory UnauthorizedAccessException?

Posted on 2010-08-23
3
Medium Priority
?
522 Views
Last Modified: 2012-05-10
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);
                }
            }
        }  
0
Comment
Question by:pointeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
daveamour earned 2000 total points
ID: 33501254
I think you need this:

while ((line = sr.ReadLine()) != null)
Also I think your using statement should be:

using (StreamReader sr = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read)))
0
 

Author Comment

by:pointeman
ID: 33501831
I discoved it's impossible to open a 'path' as a fle, doh...
Also, the 'Using' statement works much better, thanks...
0
 
LVL 19

Expert Comment

by:daveamour
ID: 33501859
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!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question