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

  • Home
  • SEARCH
  • 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 8239925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:18:46+00:00 2026-06-07T20:18:46+00:00

I am making a program where it could copy a Folder and Transfer it

  • 0

I am making a program where it could copy a Folder and Transfer it to another location, including the attribute, permissions, security settings.

So Far I got the Attribution to work, but am having problems with the permissions/security settings. Here are my code:

Directory.CreateDirectory(Destination);
DirectoryInfo DestAttribute = new DirectoryInfo(Destination);
DestAttribute.Attributes = Source.Attributes; // Copies Attributes from Source to Dest

AuthorizationRuleCollection Rule;
DirectorySecurity DestSecurity = Source.GetAccessControl();
Rule = DestSecurity.GetAccessRules(true, true, typeof(NTAccount));
DestSecurity.AddAccessRule(Rule);
DestAttribute.SetAccessControl(DestSecurity);

Anyone have any suggestion on getting this to work ?
Thank you everyone for all the help.

  • 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-07T20:18:50+00:00Added an answer on June 7, 2026 at 8:18 pm

    This appears to be a duplicate of:

    Original Question…

    (code sample from original question)

    FileInfo file1 = new FileInfo(@"c:\test.txt");
    FileInfo file2 = new FileInfo(@"c:\test2.txt");
    StreamReader sr1 = new StreamReader(file1.Open(FileMode.Open));
    StreamWriter sw1 = new StreamWriter(file2.Open(FileMode.Create));
    sw1.Write(sr1.ReadToEnd());
    sr1.Close();
    sw1.Close();
    FileSecurity ac1 = file1.GetAccessControl();
    ac1.SetAccessRuleProtection(true, true);
    file2.SetAccessControl(ac1);
    

    I put together the following method and it appears to do what you want…

    private static void FolderCopy(String sourceFolder, String destinationFolder)
    {
        DirectoryInfo sourceDirectory = new DirectoryInfo(sourceFolder);
        DirectoryInfo destinationDirectory;
    
        if (!sourceDirectory.Exists)
        {
            throw new DirectoryNotFoundException("Source folder not found: " + sourceFolder);
        }
    
        if (!Directory.Exists(destinationFolder))
        {
            destinationDirectory = Directory.CreateDirectory(destinationFolder);
        }
        else
        {
            destinationDirectory = new DirectoryInfo(destinationFolder);
        }
    
        DirectorySecurity security = sourceDirectory.GetAccessControl();
    
        security.SetAccessRuleProtection(true, true);
        destinationDirectory.SetAccessControl(security);
    
        var filesToCopy = sourceDirectory.GetFiles();
    
        foreach (FileInfo file in filesToCopy)
        {
            String path = Path.Combine(destinationFolder, file.Name);
            FileSecurity fileSecurity = file.GetAccessControl();
    
            fileSecurity.SetAccessRuleProtection(true, true);
    
            file.CopyTo(path, false);
    
            FileInfo copiedFile = new FileInfo(path);
    
            copiedFile.SetAccessControl(fileSecurity);
        }
    }
    

    Chris

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

Sidebar

Related Questions

I am using the cool map making program DIY map and i want to
I making a program and wanted to make an update function... So lets say
Im making a program for class that manages a Hotel. I have a function
I am making a program that automates the seperation of a csv file. We
I am making a program with which to save banking information (i.e., account, password,
I am currently making a program which is supposed to prompt the user to
I am making a program that graphs a line based on data inputted by
I am currently making a program that will send an email if the date
I'm making a program in Java which will automatically move all of the .png
I'm making a program on the HUFFMAN ALGORITHM where I have one class of

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.