0

My application has a folder Data which either already exists when the application is run or is created when it runs. My problem is that I can't get it to have write access. When I manually uncheck Read-only through Windows file explorer and hit Apply and OK, it's check I open its Properties again! So I'm wondering if there's a way for me to fix that or do it programmatically. The method I have for creating the folder is

    private void CreateDataFolderIfNotExists ( )
    {
        if ( !System.IO.Directory.Exists(this._datadir) )
        {
            System.IO.Directory.CreateDirectory(this._datadir);             
        }
    }

and I'm wondering if the .NET framework has some option for making the folder this._datadir have write access either when it is created or retroactively.

  • why don't you try it on your own.. you already have the code to `Create` the Directory / Folder now after you create it, try to create a file and write to that folder.. what's the problem here..?? – MethodMan Nov 10 '15 at 16:03
  • @MethodMan In my program I'm getting a runtime error `Access to path [that directory] is denied` and I'm assuming it has to do with write permissions. That's ultimately the problem I'm trying to solve with my question. – Abolish the IRS Nov 10 '15 at 16:04
  • The code you posted is fine and is not the cause of the issue. There are [SO posts](http://stackoverflow.com/questions/2316308/remove-readonly-attribute-from-directory) on removing the read-only attribute. Can you rename the directory or create a file in there through Windows Explorer? – Equalsk Nov 10 '15 at 16:10
  • 1
    The ReadOnly checkbox in Explorer does not do what you think it does. Surely the real problem is that the user account simply does not have write access to the directory because he doesn't have write access to parent directory either. Use superuser.com if you don't know how to fix that. Or whether you *should* fix that, probably not. – Hans Passant Nov 10 '15 at 16:28

0 Answers0