none
Assign a read write permissions to C drive in C# RRS feed

  • Question

  • I will be getting a string from database as \\PC0X15EZ190312\PCMFeed\.

    and also I am getting a string StuderGroup\\PCM\\9000\\Inbox

    Here PC0X15EZ190312 is my machine name or IP Address. if PCMFeed folder doesnt exists in the cdrive , i need to create a folder and subfolders.

    my questions

    Is there any way to create a folder just under c DRive. example c:\pcmFeed.

    Is it possible to give to create a folder named PCMFeed  just under C Drive and assign permissions to Service Account under which my service is running.


    is there any way i can provide permissions to the user, where the credentials are stored in the web. config.

    Please note that every things is happening through Web api call.

    Note : I am able to create a folders and subfolders if any directory alreadly exists.

     

    Tuesday, August 6, 2019 7:02 PM

Answers

  • Hi Gopi247.

    Thank you for posting here.

    Based on your description, you want to create a new folder in c# drive and provide permissions to the user.

    You could try the following code.

                DirectorySecurity securityRules = new DirectorySecurity();
                securityRules.AddAccessRule(new FileSystemAccessRule(@"Domain\account1", FileSystemRights.FullControl, AccessControlType.Allow));
    
                DirectoryInfo di = Directory.CreateDirectory(@"C:\pcmFeed", securityRules);

    If you want to know more about it, you could refer to CreateDirectory(String, DirectorySecurity).

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 7, 2019 2:11 AM
    Moderator

All replies

  • Hi Gopi247.

    Thank you for posting here.

    Based on your description, you want to create a new folder in c# drive and provide permissions to the user.

    You could try the following code.

                DirectorySecurity securityRules = new DirectorySecurity();
                securityRules.AddAccessRule(new FileSystemAccessRule(@"Domain\account1", FileSystemRights.FullControl, AccessControlType.Allow));
    
                DirectoryInfo di = Directory.CreateDirectory(@"C:\pcmFeed", securityRules);

    If you want to know more about it, you could refer to CreateDirectory(String, DirectorySecurity).

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 7, 2019 2:11 AM
    Moderator
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 9, 2019 6:51 AM
    Moderator