Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Professional C# 4.0 and .NET 4
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional C# 4.0 and .NET 4
This is the forum to discuss the Wrox book Professional C# 4.0 and .NET 4 by Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner; ISBN: 9780470502259
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C# 4.0 and .NET 4 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 28th, 2010, 08:26 PM
Registered User
 
Join Date: Mar 2010
Location: Indianapolis, IN
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Access Denied on GetFiles()method

So far, I am finding this new book to be quite useful! I am having one problem I hope you can help me with. Referring to the section on file system objects, circa p. 778, you list an example program where you reference "foreach (DirectoryInfo nextFodler in theFolder.GetDirectories())".

If I attempt to use this code against my C:\users\owner\My Documents\ folder, I get an Access Denied error. If I instead poke into one of the subfolders and do directories there, I get no problems. Apparently there are system files hidden in this folder that cause GetFiles() and GetDirectories() to fail in Vista and Win7.

I have verified that I get this error in both 2008 and 2010 versions. Do you have any advice on how to work around this problem?

Kind Regards,
Dave Smith
Indianapolis, IN
  #2 (permalink)  
Old October 1st, 2010, 12:30 PM
Wrox Author
Points: 1,163, Level: 13
Points: 1,163, Level: 13 Points: 1,163, Level: 13 Points: 1,163, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Where does the problem happen exactly? Accessing the directory within in the foreach loop? What file gives the problem? Did you catch the exception details?
With the my documents folder on my Windows 7 system I don't have a problem with hidden files.
Code:
            DirectoryInfo theFolder = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            foreach (DirectoryInfo nextFolder in theFolder.GetDirectories())
            {
                Console.WriteLine(nextFolder.Name);
            }
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
The Following User Says Thank You to ChristianNagel For This Useful Post:
urbnsurfr (October 8th, 2010)
  #3 (permalink)  
Old October 8th, 2010, 09:50 PM
Registered User
 
Join Date: Mar 2010
Location: Indianapolis, IN
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default It seems to be the difference in how we call the directory

source_dir "C:\\Users\\noz\\My Documents" string
DirectoryInfo sd = new DirectoryInfo(source_dir);

foreach (DirectoryInfo nextFolder in sd.GetDirectories())
{
Console.WriteLine(nextFolder.Name);
}
FileInfo[] files = sd.GetFiles();

In the GetDirectories() and the GetFiles() method I get the same error:
Access to the path 'C:\Users\noz\My Documents\' is denied.

However, if I instanatiate the way you made it (with the environment call):

sd = new DirectoryInfo(Environment.GetFolderPath(Environmen t.SpecialFolder.MyDocuments));


With sd instantiated this way, I do not get the access denied error. So I guess that's my way around the problem. Thanks for your help!

Kind Regards,
Dave Smith
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
401.3 Access denied due to Access Control List cforsyth .NET Framework 2.0 8 May 28th, 2009 01:56 PM
Access Denied for Download File(s) access. Kramerj BOOK: Expert One-on-One Access Application Development 0 May 27th, 2009 12:30 PM
GetFiles() Help adamcherochak ASP.NET 1.x and 2.0 Application Design 12 April 19th, 2008 07:21 AM
Access is denied. Ramakrishna General .NET 4 November 30th, 2004 09:05 AM
Access Denied tys MySQL 0 March 25th, 2004 03:46 PM



All times are GMT -4. The time now is 10:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.