Remove Read-Only Attribute On FOLDER On A Network Share

笑着哭i 提交于 2019-12-25 03:47:13

问题


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:


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



来源:https://stackoverflow.com/questions/6765991/remove-read-only-attribute-on-folder-on-a-network-share

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!