473,804 Members | 3,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryInfo.G etFiles() Access Denied errors (C#)

15 New Member
Hello everyone. I'm working on a simple utility that lists all files in a given directory with a given extension and outputs the results to a text file. I'm encountering issues while testing where the DirectoryInfo.G etFiles returns nothing. When I put a break in and check it out further, it looks like I'm getting ERROR_ACCESS_DE NIED when the GetFiles hits certain directories (for example, a System Volume Information directory).

If this were VB I'd just be sloppy and throw an Error Resume Next, lolling all the way to the bank, but obviously I don't have that option in C#. The problem is that using try/catch isn't returning any Exceptions, so I don't know what else to do. Can anyone suggest how I can handle this?

Heres's the code I'm using:

Expand|Select|Wrap|Line Numbers
  1. private void searchFiles(string drive, string extension, string savedFile)
  2. {
  3.             FileInfo saveList = new FileInfo(savedFile);
  4.             StreamWriter w = saveList.CreateText();
  5.             DirectoryInfo di = new DirectoryInfo(drive);
  6.             FileInfo[] lstFiles = di.GetFiles(extension, SearchOption.AllDirectories);
  7.  
  8.             foreach (FileInfo fi in lstFiles)
  9.             {
  10.                 w.WriteLine(fi.FullName);
  11.             }
  12.             w.Close();
  13. }
Oct 13 '07 #1
2 11657
Plater
7,872 Recognized Expert Expert
I believe you can supply permisions to directory/file accesses so that you avoid the "error".

It only returns an empty set for directories you are "not allowed" right, and not the entire thing? so is that really a problem?
Nov 1 '07 #2
cjvirus
1 New Member
Its easy... Use the code below from VB.Net:

Expand|Select|Wrap|Line Numbers
  1. Dim d As New DirectoryInfo(path)
  2.  
  3. For Each Directory As DirectoryInfo In d.GetDirectories()
  4.     If (Directory.Attributes And FileAttributes.System) <> FileAttributes.System Then
  5.         'Your code here!
  6.     End If
  7. Next
Mar 3 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1861
by: Rob | last post by:
Apologies if this is a frequently asked question but i haven't been able to find a satsifactory answer anywhere else at the moment. My problem is that i'm trying to convert an Access97 database to sql Server 2000 using the Import and Export Data wizard. I can see the list of tables but get read access errors when trying to convert them. I guess this is a security problem, because i can't see reports,forms, tables, etc. when opening the...
1
3706
by: Ron | last post by:
I have a asp.net application that uses the above class to open, get status and start/stop a service. I can get the Status of my Service, but can't start/stop it. I keep getting Access Denied errors. System.ComponentModel.Win32Exception: Access is denied I see ServiceControllerPermission class - but not sure how to use it.
2
1666
by: byrd48 | last post by:
I have a dll I use in a VS project and it seems at random, when I debug, I will get an application config error (posted below) stating that access is denied. I can debug multiple times and then out of the blue, start getting this error. Is there a way to see if another process has it locked? Thanks, Jon Server Error in '/jpg' Application.
0
5216
by: David Palau | last post by:
We have a internal company WinForms application that makes some calls out to a intranet web service (once at application start-up for some configuration info and then periodically during the life of the application for specific functional requests). We are getting System.Net.WebException with HTTP 401: Access Denied errors periodically when we are attempting some functional web service calls. However, immediately trying the web service...
0
1718
by: robgallen | last post by:
I'm having a wierd issue trying to launch a robocopy process via a web form. To cut a long story short, it works fine when I run it from the server it is hosted on, but when I access the site from my own machine, I get access denied errors. Example on server 'wwwdeploy': http://localhost/Deploy/default.aspx effectively runs this command: robocopy \\wwwdeploy\wwwroot$\project\subfolder \\wwwtest\drop\project\subfolder /S /Z
2
1293
by: krallabandi | last post by:
Do you have any idea about the below errors? Access to the path "C:\DOCUME~1\P005715\ASPNET\LOCALS~1\Temp\cumhnc6b.cmdline" is denied. Access to the path "C:\DOCUME~1\P005715\ASPNET\LOCALS~1\Temp\fbc8tyiu.cmdline" is denied. Access to the path
2
23047
by: =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= | last post by:
Hi, I've been trying to use Directory.GetFiles() and also DirectoryInfo.GetFiles() to list files on a remote server using "\\server_name\dir_name" like paths. It works fine on a test windows app, but I get an access error message when the code is running on a asp.net app. First I thought it was just a matter of credentials, so I started to use windows authentication and impersonate the current user, but I still got the same message.
1
1829
by: Rick | last post by:
I've migrated a web site from VS 2003 to VS 2005. After pushing the a Windows Server 2003 web server. The Framework 2.0 web site works when I go to test it. I'll start working on something else come back later and I start getting Access Denied errors on System.Data or System.Transaction, these files are set up as assemblies in the machine.config and set to the correct version. The only way to fix it is to restart ASP.NET. Any suggestions?
2
3191
by: P1 | last post by:
Hey guys, I'm totally out of my league here, I don't even know how I got stuck with this problem, it's obviously a webmaster issue and I'm just a lowly net admin. The error: Starts here 9/5/2008 6:00:41 PM Microsoft VBScript runtime error '800a0046'
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.