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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:00:27+00:00 2026-05-26T12:00:27+00:00

hi i am working on c# project and i try to lock a file

  • 0

hi i am working on c# project and i try to lock a file from being opened , copied or even deleted by using that code :

FileInfo fi = new FileInfo(textBox1.Text);
            FileSecurity ds = fi.GetAccessControl();
            ds.AddAccessRule(new FileSystemAccessRule("Authenticated Users",      FileSystemRights.FullControl, AccessControlType.Deny));
            fi.SetAccessControl(ds);

but when i open the file , it is opened and can be deleted , is there anything wrong on my code ?

by the way , that code works perfectly on anywhere but flash drive , i can block editing or copying files from computer , but on flash drive the application is useless .

  • 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-05-26T12:00:27+00:00Added an answer on May 26, 2026 at 12:00 pm

    What filesystem does your flash drive have? I’m guessing FAT32, rather than NTFS.

    FAT32 has no concept of per-file ACLs (or as far as I know, no concept of ACLs whatsoever).

    See this article:

    http://technet.microsoft.com/en-us/library/cc783530(WS.10).aspx

    On a FAT or FAT32 volume, you can set permissions for shared folders but not for files and folders within a shared folder. Moreover, share permissions on a FAT or FAT32 volume restrict network access only, not access by users working directly on the computer.

    The only option will be to open the file in exclusive access mode to prevent others from changing it while you are reading it.

    See this question (stolen from Vitaliy’s comment):

    How to lock file

    The code from the accepted answer:

    using (FileStream fs = 
           File.Open("MyFile.txt", FileMode.Open, FileAccess.Read, FileShare.None))
    {
        // use fs
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While working a project tonight, I ended up using one .js resource file for
I try to run a working rails project from OSX to Debian. I use
I'm working on a project that uses both .net and java, using zeromq to
I'm working on project that lets users choose some scientific authors and columnists and
I am working a project with many NUnit tests, that were already written long
I am working on project -online file management where we have to tore file
I am working on project in JSF, using Tomcat 7. The application will have
I have a fully working Setup project within Visual Studio 2008 that takes inputs
I'll try to be concise this time around! I'm still working Project Euler, this
I only added to an existing fully working project, the file com/android/vending/billing/IMarketBillingService.aidl (I didn't

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.