다음을 통해 공유


빠른 시작: 민감도 레이블 설정 및 가져오기(C#)

이 빠른 시작에서는 MIP 파일 SDK를 더 많이 사용하는 방법을 보여 줍니다. 이전 빠른 시작에서 나열한 민감도 레이블 중 하나를 사용하여 파일 처리기를 사용하여 파일의 레이블을 설정/가져옵니다. 파일 처리기 클래스는 지원되는 파일 형식에 대한 레이블 설정/가져오기 또는 보호를 위한 다양한 작업을 노출합니다.

필수 조건

아직 완료하지 않은 경우 계속하기 전에 다음 필수 조건을 완료해야 합니다.

논리를 추가하여 민감도 레이블을 설정하고 가져옵니다.

파일 엔진 개체를 사용하여 파일에 민감도 레이블을 설정하고 가져오는 논리를 추가합니다.

  1. 솔루션 탐색기를 사용하여 Main()' 메서드의 구현이 포함된 프로젝트에서 .cs 파일을 엽니다. 기본 이름은 프로젝트 생성 시 지정한 이름을 포함한 프로젝트와 동일합니다.

  2. 본문 끝의 Main() 주석 뒤에 var fileEngine = 다음 //Application Shutdown 코드를 삽입합니다.

      //Set paths and label ID
      string inputFilePath = "<input-file-path>";
      string actualFilePath = inputFilePath;
      string labelId = "<label-id>";
      string outputFilePath = "<output-file-path>";
      string actualOutputFilePath = outputFilePath;
    
      //Create a file handler for that file
      //Note: the 2nd inputFilePath is used to provide a human-readable content identifier for admin auditing.
      var handler = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(inputFilePath, actualFilePath, true)).Result;
    
      //Set Labeling Options
      LabelingOptions labelingOptions = new LabelingOptions()
      {
           AssignmentMethod = AssignmentMethod.Standard
      };
    
      // Set a label on input file
      handler.SetLabel(fileEngine.GetLabelById(labelId), labelingOptions, new ProtectionSettings());
    
      // Commit changes, save as outputFilePath
      var result = Task.Run(async () => await handler.CommitAsync(outputFilePath)).Result;
    
      // Create a new handler to read the labeled file metadata
      var handlerModified = Task.Run(async () => await fileEngine.CreateFileHandlerAsync(outputFilePath, actualOutputFilePath, true)).Result;
    
      // Get the label from output file
      var contentLabel = handlerModified.Label;
      Console.WriteLine(string.Format("Getting the label committed to file: {0}", outputFilePath));
      Console.WriteLine(string.Format("File Label: {0} \r\nIsProtected: {1}", contentLabel.Label.Name, contentLabel.IsProtectionAppliedFromLabel.ToString()));
      Console.WriteLine("Press a key to continue.");
      Console.ReadKey();
    
  3. 첫 번째 Main()의 끝에서 첫 번째 빠른 시작에서 만든 애플리케이션 종료 블록을 찾아서 처리기 줄의 주석을 제거합니다.

    // Application Shutdown
    handler = null;
    fileEngine = null;
    fileProfile = null;
    mipContext = null;
    
  4. 다음 값을 사용하여 소스 코드의 자리 표시자 값을 바꿉니다.

    플레이스홀더 가치
    <입력 파일 경로> 테스트 입력 파일의 전체 경로(예: c:\\Test\\Test.docx.
    <label-id> 이전 빠른 시작의 콘솔 출력에서 복사한 민감도 레이블 ID입니다. 예를 들면 다음과 f42a3342-8706-4288-bd31-ebb85995028z같습니다.
    <출력 파일 경로> 입력 파일의 레이블이 지정된 복사본인 출력 파일의 전체 경로입니다. 예를 들면 다음과 c:\\Test\\Test_labeled.docx같습니다.

응용 프로그램 구축 및 테스트

클라이언트 애플리케이션을 빌드하고 테스트합니다.

  1. Ctrl-SHIFT-B(솔루션 빌드)를 사용하여 클라이언트 애플리케이션을 빌드합니다. 빌드 오류가 없는 경우 F5(디버깅 시작)를 사용하여 애플리케이션을 실행합니다.

  2. 프로젝트가 성공적으로 빌드되고 실행되는 경우 애플리케이션은 SDK가 메서드를 호출할 때마다 ADAL을 통해 인증을 요청하는 메시지를 표시할 수 있습니다AcquireToken(). 캐시된 자격 증명이 이미 있는 경우 로그인하고 레이블 목록을 확인하고 적용된 레이블 및 수정된 파일에 대한 정보를 확인하라는 메시지가 표시되지 않습니다.

Personal : 73c47c6a-eb00-4a6a-8e19-efaada66dee6
Public : 73254501-3d5b-4426-979a-657881dfcb1e
General : da480625-e536-430a-9a9e-028d16a29c59
Confidential : 569af77e-61ea-4deb-b7e6-79dc73653959
      Recipients Only (C) : d98c4267-727b-430e-a2d9-4181ca5265b0
      All Employees (C) : 2096f6a2-d2f7-48be-b329-b73aaa526e5d
      Anyone (not protected) (C) : 63a945ec-1131-420d-80da-2fedd15d3bc0
Highly Confidential : 905845d6-b548-439c-9ce5-73b2e06be157
      Recipients Only : 05ee72d9-1a75-441f-94e2-dca5cacfe012
      All Employees : 922b06ef-044b-44a3-a8aa-df12509d1bfe
      Anyone (not protected) : c83fc820-961d-40d4-ba12-c63f72a970a3
Press a key to continue.

 Applying Label ID 074e457c-5848-4542-9a6f-34a182080e7z to c:\Test\Test.docx
 Committing changes

 Label committed to file: c:\Test\Test_labeled.docx
 Press any key to continue.

 Getting the label committed to file: c:\Test\Test_labeled.docx
 File Label: Confidential
 IsProtected: false   
 Press any key to continue.

출력 파일을 열고 문서의 정보 보호 설정을 시각적으로 검사하여 레이블의 응용 프로그램을 확인할 수 있습니다.

비고

Office 문서에 레이블을 지정하지만 액세스 토큰을 가져온 Microsoft Entra 테넌트의 계정을 사용하여 로그인하지 않은 경우(및 민감도 레이블이 구성된 경우) 레이블이 지정된 문서를 열기 전에 로그인하라는 메시지가 표시될 수 있습니다.