Remove Read-Only Attribute On FOLDER On A Network

2019-08-22 06:17发布

I am having an issue that is really killing me.

I have a directory that when I go to the properties window, shows Read-Only as partially checked (not a full check box, but the box is filled).

So I looked in the directory and I checked all the files, none of them have the read-only attribute. Only the folder has it, and only partially.

I tried the following code:

if (directoryInfo.Exists)
{
    try
    {
        directoryInfo.Attributes &= ~FileAttributes.ReadOnly;

        foreach (FileInfo f in directoryInfo.GetFiles())
        {
           f.IsReadOnly = false;
        }
    }
    catch (Exception e)
    {
        throw e;
    }
}

It still did not work. I can right click on the folder and manually remove the read-only permissions but I need to be able to do this in code. The code executes but does not error.

Anyone have any idea what the issue could be? My only guess is because the folder is on a network share (in the form of \\computer\folder\subfolder), that I might need special rights in order to change permissions on a folder?

Please someone help.

Thanks in advance

1条回答
小情绪 Triste *
2楼-- · 2019-08-22 07:01

readonly on folders is used by Windows internally... if you really need to change it then is some work involved (Registry and changing alot of folders)... see http://support.microsoft.com/kb/256614/en-us

Why do you need to make that change ?

EDIT - some information on Powershell and TFS:

http://codesmartnothard.com/ExecutingPowerShellScriptsOnRemoteMachinesWithTFS2010AndTeamDeploy2010.aspx

http://blogs.msdn.com/b/yao/archive/2011/06/15/tfs-integration-pack-and-scripting-using-powershell.aspx

or try a normal "batch file" (.bat) with "attrib -r" on the folder

查看更多
登录 后发表回答