Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:57:51+00:00 2026-06-13T10:57:51+00:00

My application uses the .NET object Directory.GetFiles() The actual overload I’m using is var

  • 0

My application uses the .NET object Directory.GetFiles()

The actual overload I’m using is

var allFiles = Directory.GetFiles("C:\\Users\\Dave", "*.*", SearchOption.AllDirectories);

The issue is when the source folder is C:\Users\UserName as it then tries to look through application data folder.

When it tries to read from the application data folder, an exception is thrown:

“Access to the path ‘C:\Users\Dave\AppData\Local\Application
Data’ is denied.”

So, my question is does any one have an opinion as to my options? I would assume I have to either change the way I collect all the files or, there may be a built in overload or method which will allow me to continue this (which I clearly don’t know about).

If it helps, the goal of this is to take all the files retrieved by Directory.GetFiles() and ‘paste’ them else where (a glorified copy and paste/back up). I’m actually not too worried about system files, just ‘user files’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:57:52+00:00Added an answer on June 13, 2026 at 10:57 am

    The directory %AppData% is a system-protected directory. Windows will try to block any access to this directory as soon as the access was not authorized (An access from another user than the Administrator).

    Only the Administrator by default has privileges to read and write from/to this directory.

    Alternatively, you can catch the exception and see if the result is Access Denied. Then, you may prompt the user to run as an Administrator to complete this step. Here’s a simple example to prompt the user to run as Administrator

    try
    {
         var allFiles = Directory.GetFiles("C:\\Users\\Dave", "*.*", SearchOption.AllDirectories);
    }
    catch (Exception EX)
    {
         if (EX.Message.ToLower().Contains("is denied."))
         {
              ProcessStartInfo proc = new ProcessStartInfo();
              proc.UseShellExecute = true;
              proc.WorkingDirectory = Environment.CurrentDirectory;
              proc.FileName = Application.ExecutablePath;
              proc.Verb = "runas"; //Required to run as Administrator
              try
              {
    
              Process.Start(proc);
    
              }
              catch
              {
                   //The user refused to authorize
              }
         }
    }
    

    However, you may always prompt the user to authorize when your application launches which is NOT always RECOMMENDED. To do this, you’ll have to edit your project app.manifest file

    Locate and change the following line

    <requestedExecutionLevel level="asInvoker" uiAccess="false" />
    

    to

    <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
    

    Thanks,

    I hope you find this helpful 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have compiled a .NET application using Any CPU option. This .NET application uses
I have an ASP.Net 2.0 application that uses integrated Windows Authentication to authenticate/authorize users.
My application uses asp.net 4, C# and Entity Framework. My database contains a table
I have an application that uses the .NET framework 3.5. I am building this
I have a monodroid application that uses a .net library that contains normal .resx
I'm writing an ASP.net application that uses Windows Identity Foundation. My ASP.net application uses
I'm trying to design an entity model for an application that uses ASP.Net membership
I have an ASP.NET application that uses a custom .NET library (a .DLL file).
We just came across a weird bug in our application that uses the asp.net
I have a .NET application that uses some API calls, for example GetPrivateProfileString .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.