none
Network - file upload RRS feed

  • Question

  • Hi,

    I am facing issues while saving the files to the network path. Please find the below code and help me on this issue!

     string strPath = @"Y:\test"; //Y drive mapped to the folder "\\Server2\\NetworkFiles\"            
                if (!Directory.Exists(strPath))
                {
                    System.Security.AccessControl.DirectorySecurity dirSecurity = new System.Security.AccessControl.DirectorySecurity();
                    dirSecurity.AddAccessRule(
                        new System.Security.AccessControl.FileSystemAccessRule("Everyone",
                        System.Security.AccessControl.FileSystemRights.FullControl,
                        System.Security.AccessControl.InheritanceFlags.ContainerInherit | System.Security.AccessControl.InheritanceFlags.ObjectInherit,
                        System.Security.AccessControl.PropagationFlags.None,
                        System.Security.AccessControl.AccessControlType.Allow)
                    );
                    // Create the new folder with the custom ACL.
                    System.IO.Directory.CreateDirectory(strPath, dirSecurity);

    Note: Running the code with same account which is having admin access to that server2. Also, have tried the path "\\Server2\\NetworkFiles\\test" in the code but no luck.

    Please let me know if you need any information!

    Regards,

    Kumar

    Sunday, October 15, 2017 1:26 PM

Answers

  • I resolved the issue by providing the path "@\\server\NetworkFiles".

    Regards,

    Kumar

    • Marked as answer by KumarSP2013 Monday, October 16, 2017 10:24 AM
    Monday, October 16, 2017 10:24 AM

All replies

  • Hello,

     Before you can create Directories on a mapped Network Drives, when

    its endpoint is an actual hard drive or a sub-directory, as in your code.

    The parent permissions must be set on the Root for drives/folders. So,

    you need the directory "NetworkFiles" on the Server2 to allow for the

    creation of sub-directories from group permissions "Everyone". But, this

    is bad idea as "Everyone" can change the directory "test" contents and

    anything else contained under directory "NetworkFiles".

     Hope this helps :)

    Sunday, October 15, 2017 8:48 PM
  • Hello,

    Thanks for your response. I am not getting any access denied error, Getting the error "Could not find a part of the path 'Y:\test'.".(I can change the security Everyone)

    Please advise.

    Regards,

    Kumar

    Monday, October 16, 2017 3:45 AM
  • Hello,

     Based on your code, I designed a Console App and did not get an error.

    I don't know why your project has encountered a problem except that

    your app is logon without sufficient user rights or you are not showing

    all the details. This is what I did on my PC running Win7, VS 2012, Admin.

     1. On Drive D: Root created a directory called "NetworkFiles"

     2. Added Sharing rights to "D:\NetworkFiles" for "Everyone" with Read/Write.

     3. Mapped "Y:" network drive to "D:\NetworkFiles" aka "\\USER-PC\NetworkFiles"

     4. Executed your app code exactly as you presented in posting, without errors.

     5. Viewed the contents of Network Drive "Y:" and verified the new directory "test"

     

     I don't know why your app failed. Please provide exact details of the error.

     Thanks :)

    Monday, October 16, 2017 6:08 AM
  • Hi,

    It's strange, Trying the same code. Please refer the screenshot and suggest me!(Manually can create the folder with the same account)

    

    Regards,

    Kumar


    • Edited by KumarSP2013 Monday, October 16, 2017 8:05 AM
    Monday, October 16, 2017 7:54 AM
  • I resolved the issue by providing the path "@\\server\NetworkFiles".

    Regards,

    Kumar

    • Marked as answer by KumarSP2013 Monday, October 16, 2017 10:24 AM
    Monday, October 16, 2017 10:24 AM