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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:37:39+00:00 2026-05-26T05:37:39+00:00

I am trying to implement a security on a single file to prevent either

  • 0

I am trying to implement a security on a single file to prevent either accessing the file or deleting it here is the code :

//Create file
FileStream oFileStreamDec = new FileStream(@"C:\Decrypted_AMS.cfg", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
oFileStreamDec.Write(DecryptedXML, 0, DecryptedXML.Length);
//Create access rules
FileSystemAccessRule oAccessRuleFullControl = new FileSystemAccessRule(WindowsIdentity.GetCurrent().Name, FileSystemRights.FullControl, AccessControlType.Allow);
//Create file security and apply rules to it
FileSecurity oFileSecurity = new FileSecurity(@"C:\Decrypted_AMS.cfg", AccessControlSections.All);
oFileSecurity.AddAccessRule(oAccessRuleFullControl);
//Here is the problem !!!!!!!
oFileStreamDec.SetAccessControl(oFileSecurity);
oFileStreamDec.Close();

I have tried to open the file again after closing the stream and setting the access control but same problem occurred, i have tried also it on a normal file other than a file stream and the same too, I have an admin account with all permissions so What is the problem and how to Solver it ?

  • 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-26T05:37:40+00:00Added an answer on May 26, 2026 at 5:37 am

    try this,

    FileStream oFileStreamDec = new FileStream(@"C:\Decrypted_AMS.cfg", FileMode.Create, FileAccess.ReadWrite, FileShare.None);
    oFileStreamDec.Write(DecryptedXML, 0, DecryptedXML.Length);
    // Close the File first
    oFileStreamDec.Close();
    //Create file security and apply rules to it
    FileSecurity oFileSecurity = new FileSecurity();
    oFileSecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("Everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
    System.IO.File.SetAccessControl(@"C:\Decrypted_AMS.cfg", oFileSecurity);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement some custom security code into SSRS 2008 (not R2)
I'm trying to implement single sign-on for a web portal. I've written some code
Am trying to implement a generic way for reading sections from a config file.
While trying to implement an MVC file upload example on Scott Hanselman's blog. I
I am using form-login for security and I am trying to implement an authentication
I am trying to implement security for the following architecture: Web tier: Tomcat 7
I'm trying to implement row-based security checks for Django models. The idea is that
I'm trying to implement a very granular security module in an ASP.NET MVC 3
I'm trying to implement adaptive payments but keep getting this weird error. Here's the
I'm trying to implement spring security acl into a project. After building the main

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.