如何在C#中创建具有只读访问权限的共享文件夹? 我看到this示例,但它也提供了写访问权
答案 0 :(得分:3)
请参阅此链接Working with Shared Folders
IWHSInfo2 info = new WHSInfoClass();
IShareInfo2 share = info.CreateShare("SharedFolderName", "SharedFolderDescription", 0);
WHSUserPermission perm1 = new WHSUserPermission();
perm1.userName = "User1";
perm1.permission = WHSSharePermissions.WHS_SHARE_READ_ONLY;
WHSUserPermission perm2 = new WHSUserPermission();
perm2.userName = "User2";
perm2.permission = WHSSharePermissions.WHS_SHARE_READ_WRITE;
Array permsArray = Array.CreateInstance(typeof(WHSUserPermission), 2);
permsArray.SetValue(perm1, 0);
permsArray.SetValue(perm2, 1);
share.SetPermissions(permsArray);
再见。
答案 1 :(得分:1)
试试这个:
File.SetAttributes("C:\Path\To\Folder", FileAttributes.ReadOnly);