none
How to fix Access to the path '...' is denied. error in C#

    Question

  • I'm on windows 7 creating a desktop aplication in Visual C# 2010.
    The error's produced here:

    void Copymove(string file) 
    {
     File.Copy(Environment.GetFolderPath(Environment.SpecialFold er.MyDocuments), "../../contenidos/" + file);
    }

    The exact error:
    Access to the path 'C:\Users\Daniel\Documents' is denied.

    I've already tried modifying the app.manifest and it does not work... It's been about 5 hours i've been trying to fix this. Any ideas?

    Thanks in advance.

    Sunday, June 24, 2012 6:51 PM

Answers

  • On 6/24/2012 4:29 PM, belohlavek wrote:
    > Did everything you said and still can't change the read only setting on
    > the folder I want to access.
     
    There are two user groups on the folder. The Admin group and your
    username\machine-name\username and if the those two accounts don't match
    in the permissions for write access, then it's going to be access
    denied, because username\machine-name\username (that's your username
    account) doesn't have the same rights as admin and admin is being
    superseded by user account.
     
    Your user account is in two groups, and one is in conflict with the
    other, and they must both match. That's just the way it is in Vista and
    Win 7, which are not XP.
     
    • Marked as answer by Alexander Sun Monday, July 09, 2012 6:25 AM
    Sunday, June 24, 2012 8:45 PM

All replies

  • Maybe the logged user does not have administrator role, so you are unable to work with folders inside someone else`s User folder.

    Mitja

    Sunday, June 24, 2012 6:54 PM
  • It's my Documents folder, I mean, Daniel is my user and I'm administrator.
    Sunday, June 24, 2012 7:05 PM
  • On 6/24/2012 3:05 PM, belohlavek wrote:
    > It's my Documents folder, I mean, Daniel is my user and I'm administrator.
     
    This sounds like Vista or Windows 7 issue. If it's either one of those,
    then you are not admin on that machine with full-rights and UAC enabled
    like you were on XP.
     
    Sunday, June 24, 2012 7:28 PM
  • Yup, read the first line of my message:

    "I'm on windows 7 creating a desktop aplication in Visual C# 2010."

    Never mind that, how can I get full access?


    Sunday, June 24, 2012 7:35 PM
  •             string userDocumentsFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string[] files = System.IO.Directory.GetFiles(userDocumentsFolder);
                string fileContents = System.IO.File.ReadAllText(files[3]);  // I know this one is a text file
               

    This works on my Windows 7.  I know the file at index 3 is a text file.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Sunday, June 24, 2012 7:38 PM
  • How to Take Ownership in Windows 7

    1. Locate the file or folder on which you want to take ownership in windows explorer

    2. Right click on file or folder and select “Properties” from Context Menu

    3. Click on Security tab

    4. Click on “Advance”

    5. Now click on Owner tab in Advance Security Settings for User windows

    6. Click on Edit Button and select user from given Change Owner to list if user or group is not in given list then click on other users or groups. Enter name of user/group and click ok.

     7. Now select User/group and click apply and ok. (Check “Replace owner on sub containers and objects” if you have files and folder within selected folder)

    8. Click ok when Windows Security Prompt is displayed

    9. Now Owner name must have changed.

    10. Now click Ok to exist from Properties windows

    Once you have taken the ownership of file or folder next part comes is Granting Permissions to that file/folder or object.

     

    How to Grant Permissions in Windows 7

    1. Locate the file or folder on which you want to take ownership in windows explorer

    2. Right click on file or folder and select “Properties” from Context Menu

    3. Click on Edit button in Properties windows Click ok to confirm UAC elevation request.

    4. Select user/group from permission windows or click add to add other user or group.

    5. Now under Permission section check the rights which you want to grant i.e check “Full Control” under the “Allow” column to assign full access rights control permissions to Administrators group.

    6. Click Ok for changes to take effect and click ok final ok to exit from Properties window.

    Now you can access files of folder in windows 7 with full permissions and take full control.

    ---

    You can even check here: 

    http://forum.thewindowsclub.com/windows-tips-tutorials-articles/18379-how-take-ownership-full-control-permissions-files-folders-windows.html


    Mitja


    Sunday, June 24, 2012 7:39 PM
  • On 6/24/2012 3:35 PM, belohlavek wrote:
    > Yup, read the first line of my message:
    >
    > "I'm on windows 7 creating a desktop aplication in Visual C# 2010."
    >
    > Never mind that, how can I get full access?
    >
    >
     
    Most likely, you are not running VS with admin rights. So you are being
    denied access if you are trying to do this and running the program in
    the VS IDE.
     
    If this is the case, you should right-click the VS short-cut, go to
    Properties, go to the Advanced button and set run as administrator.
     
    Sunday, June 24, 2012 7:46 PM
  • I've got 2 groups, Administrator and AdministratorS

    Which one should I choose?

    Never mind, is Administrators
    • Edited by belohlavek Sunday, June 24, 2012 8:16 PM found it on the link posted
    Sunday, June 24, 2012 8:15 PM
  • Did everything you said and still can't change the read only setting on the folder I want to access.
    Sunday, June 24, 2012 8:29 PM
  • On 6/24/2012 4:29 PM, belohlavek wrote:
    > Did everything you said and still can't change the read only setting on
    > the folder I want to access.
     
    There are two user groups on the folder. The Admin group and your
    username\machine-name\username and if the those two accounts don't match
    in the permissions for write access, then it's going to be access
    denied, because username\machine-name\username (that's your username
    account) doesn't have the same rights as admin and admin is being
    superseded by user account.
     
    Your user account is in two groups, and one is in conflict with the
    other, and they must both match. That's just the way it is in Vista and
    Win 7, which are not XP.
     
    • Marked as answer by Alexander Sun Monday, July 09, 2012 6:25 AM
    Sunday, June 24, 2012 8:45 PM