如何在 Sharepoint 中隐藏文件夹
我还需要在以下代码中添加什么来确保该文件夹是隐藏的或只读的?
SPListItem createFolder = myDocLib.Folders.Add(myDocLib.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, "Folder444");
文件夹.Update();
What else I need to add to following code to make sure the folder is hidden or read only?
SPListItem createFolder = myDocLib.Folders.Add(myDocLib.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, "Folder444");
folder.Update();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与实际列表不同,文件夹不能按正常意义上“隐藏”。也就是说,您无法使其对 UI 不可见,但仍具有与其关联的所有正常访问级别(例如,传统的工作流程历史记录列表以这种方式隐藏)。在某种程度上,当涉及到文件夹时,隐藏和使其只读的目标是一致的,因为两者都是通过权限来实现的。从技术上讲,您可以通过复杂的视图过滤器来降低特定项目的可见性,但这只会改变视图级别的内容。
列表项(即文件夹)的可见性取决于您是否对该项目具有权限。真正“隐藏”列表项的唯一方法是从该列表项中删除某人的所有权限。为了使文件夹变为只读,您需要从该文件夹中删除所有“添加”、“编辑”和“删除”权限。如果您仍然拥有默认的 SharePoint 权限级别(完全控制、设计、贡献和读取),则只需将所有内容重新分配为读取即可实现此目标。
下面是一个代码示例,我用它来对所有用户隐藏讨论(这是一个文件夹),“工程师”组中的用户除外,该讨论对“工程师”组是只读的。
编辑
分配多个实例时,这取决于您是执行所有组还是仅执行子集。我将列出所有组的代码,因为这是您直接询问的。
如果您只想对组的子集执行此操作,则可以定义所有这些组的名称列表,执行
foreach (string groupName in groupList)
,并将在循环中,指定SPPrincipal smith = web.SiteGroups[groupName];
。Unlike actual lists, a Folder cannot be made "hidden" in the normal sense. That is, you cannot make it invisible to the UI, but still have all the normal access levels associated with it (for example, the traditional Workflow History list is hidden in this fashion). In a way, your goals of hiding and making it read-only coincide when it comes to folders, as both are accomplished by Permissions. You can technically reduce the visibility of a particular item through a complicated view filter, but that would only change things on the view level.
The visibility of a list item, which a Folder is, is based on whether you have permissions on that item. The only way to truly "hide" a list item is to remove all permissions of a person from that list item. In order to make a folder read-only, you would remove all Add, Edit, and Delete permissions from the folder. If you still have the default SharePoint permission levels (Full Control, Design, Contribute, and Read), then simply reassigning everything to Read will accomplish this goal.
Here is an example of code that I use to make a discussion (which is a folder) hidden from all users except those in the group "Engineers", to whom it is read-only.
EDIT
When assigning multiple instances, it depends on whether you are doing all of the groups or just a subset. I'll list the code for all groups since that is what you are directly asking.
If you wanted to do it only for a subset of groups, you would define a list of the names of all of those groups, do a
foreach (string groupName in groupList)
, and as the first line of the loop, specifySPPrincipal smith = web.SiteGroups[groupName];
.谢谢短号。这是使文件夹只读的方法。再次感谢您的帮助...
Thank you Cornet. Here is the method that makes a folder read only. THANKS AGAIN FOR YOUR HELP...