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 8450233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:54:58+00:00 2026-06-10T10:54:58+00:00

In my network, there are some files whose access is simply blocked. A user

  • 0

In my network, there are some files whose access is simply blocked.

A user cannot open nor read the file.

When I try to open the file, the only message that I get is “Access Denied”.

 bool isReadOnly = ((File.GetAttributes(Path) & FileAttributes.ReadOnly) ==   FileAttributes.ReadOnly);

I tried other options available under FileAttributes class. Nothing is matched for “Access Denied”.

In short, how do I know whether a file is access-denied to me or not in c#. I am using WPF and visual studio .net 2010

Whenever I try to access it through code, I simply get an exception. When I try to open it manually I get something like “Access Denied.”

try
{
 IEs = from file in Directory.EnumerateFiles(sDirectoryToBeSearched, sValidExtensions, SearchOption.AllDirectories)
                      from str in File.ReadLines(file)
                      where (str.IndexOf(sSearchItem, StringComparison.OrdinalIgnoreCase) >= 0)
                      select file;
}

  catch
 {
      MessageBox ("Exception arised");
 }

Even If used try catch, exception is not handled because of LINQ query. Any solutions ?>

  • 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-10T10:55:00+00:00Added an answer on June 10, 2026 at 10:55 am

    Instead of using LINQ try using recursion, that way if a file or folder access is denied the rest of procedure will continue. Example bellow.

    private void SearchDirectory(string folder)
    {
        foreach (string file in Directory.GetFiles(folder))
        {
            try 
            {
                // do work;
            }
            catch 
            {
                // access to the file has been denied
            }
        }
        foreach (string subDir in Directory.GetDirectories(folder))
        {
            try 
            {   
                 SearchDirectory(subDir);
            }
            catch 
            {
                // access to the folder has been denied
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some way to authenticate as a local (not network) user in order
Is there better use of available storage space and faster network access using the
Network file systems are offered by Windows and (L)Unix. Is there one for IBM
My web service needs to open some files located on a remote computer. From
I am doing a command line app that needs to read some files and
In russian social network there is a functionality to play music online. Nothing special
Is it possible to make sure my thread reacts on whenever there is network
Is there a cross-platform network library for the iPhone? Is ACE available for the
Is there any way to retrieve all friends in a particular network? For example,
Is there a tool that will allow me to issue commands over the network

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.