2010-04-23 4 views
1

폴더를 숨기거나 읽기 전용으로하려면 다음 코드에 추가해야 할 사항이 있습니까?Sharepoint에서 폴더를 숨기는 방법

SPListItem createFolder = myDocLib.Folders.Add (myDocLib.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, "Folder444");

folder.Update();

답변

5

실제 목록과 달리 폴더는 정상적인 의미에서 "숨김"으로 만들 수 없습니다. 즉, UI에서 보이지 않게 할 수는 있지만 일반적인 모든 액세스 수준은 그대로 유지됩니다 (예 : 기존 워크 플로 기록 목록은이 방식으로 숨겨 짐). 한 가지 방법으로, 폴더에있을 때 읽기 전용으로 숨기거나 만들기위한 목표는 사용 권한에 따라 다르기 때문에 일치시킵니다. 복잡한보기 필터를 통해 기술적으로 특정 항목의 가시성을 줄일 수는 있지만보기 수준에서만 변경됩니다.

폴더가있는 목록 항목의 표시 여부는 해당 항목에 대한 사용 권한 여부에 따라 결정됩니다. 실제로 목록 항목을 "숨기는"유일한 방법은 해당 목록 항목에서 모든 사람의 사용 권한을 제거하는 것입니다. 폴더를 읽기 전용으로 만들려면 폴더에서 모든 추가, 편집 및 삭제 권한을 제거하십시오. 여전히 기본 SharePoint 권한 수준 (모든 권한, 디자인, Contribute 및 읽기)이있는 경우 모든 항목을 읽기에 다시 할당하면이 목표를 달성 할 수 있습니다.

다음은 읽기 전용 인 "엔지니어"그룹의 사용자를 제외한 모든 사용자가 숨긴 토론 (폴더)을 만드는 데 사용하는 코드의 예입니다.

// I excluded these two variable declarations because they were specific to 
// my situation. 
// Giving you my variable declarations would be misleading, since this is 
// meant to be a generic code sample. 
// SPListItem folder is the folder I am working on. 
// SPWeb web is the SPWeb for the site I am on. 
if (!folder.HasUniqueRoleAssignments) 
{ 
    folder.BreakRoleInheritance(false); //Setting false erases all permissions, so now the folder is hidden from everyone. 
    folder.SystemUpdate(false); 
} 
SPRoleDefinition role = web.RoleDefinitions["Read"]; 
SPPrincipal smith = web.SiteGroups["Engineers"]; //You would replace "Engineers" with the name of whatever group you want to have read permissions. Or, use web.SiteUsers[] to get a specific user. 
SPRoleAssignment roleAssignment = new SPRoleAssignment(smith); 
roleAssignment.RoleDefinitionBindings.Add(role); 
folder.RoleAssignments.Remove(smith); //If I have already assigned a different permission, this will clear it so that I ensure that the only permission is Read. 
folder.RoleAssignments.Add(roleAssignment); //This sets it to Read-Only for these people. 
folder.SystemUpdate(false); 

편집

여러 인스턴스를 할당 할 때, 당신이 그룹 또는 하위 집합의 모든 일을하는지에 따라 다릅니다. 그게 바로 당신이 직접 물어 보는 것이기 때문에 나는 모든 그룹의 코드를 열거 할 것입니다. 만 그룹의 부분 집합을 위해 그것을하고 싶었다면

if (!folder.HasUniqueRoleAssignments) 
{ 
    folder.BreakRoleInheritance(false); //Setting false erases all permissions, so now the folder is hidden from everyone. 
    folder.SystemUpdate(false); 
} 
SPRoleDefinition role = web.RoleDefinitions["Read"]; 
SPRoleAssignment roleAssignment; 
foreach (SPPrincipal smith = web.SiteGroups) 
{ 
    roleAssignment = new SPRoleAssignment(smith); 
    roleAssignment.RoleDefinitionBindings.Add(role); 
    folder.RoleAssignments.Remove(smith); 
    folder.RoleAssignments.Add(roleAssignment); 
} 
folder.SystemUpdate(false); 

, 당신은 그 모든 그룹의 이름 목록을 정의한 foreach (string groupName in groupList)을, 루프의 첫 번째 라인으로, SPPrincipal smith = web.SiteGroups[groupName];을 지정합니다.

+0

Sharepoint에서 폴더가 작동하는 방식에 대한 코드와 세부 정보는 ccornet에게 감사드립니다. 고마워. –

+0

@Rosh 요청 된 코드를 제공하는 수정 된 답변. –

+0

좋아요. 감사. 코르셋 –

2

고맙습니다. 코넷. 다음은 폴더를 읽기 전용으로 만드는 방법입니다. 다시 귀하의 도움에 감사드립니다 ...

관련 문제