DocumentBase.ProtectDocument 메서드

캐시된 데이터가 저장된 후 문서에 암호 보호를 다시 적용할 수 있는 옵션을 제공합니다.

네임스페이스:  Microsoft.Office.Tools.Word
어셈블리:  Microsoft.Office.Tools.Word.v4.0.Utilities(Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

구문

‘선언
Protected Overridable Sub ProtectDocument
protected virtual void ProtectDocument()

설명

문서가 암호를 사용하여 보호되어 있고 이 문서에 런타임에 변경될 수 있는 캐시된 데이터가 들어 있는 경우 Word용 문서 수준 프로젝트에서 이 메서드를 재정의합니다.이 메서드를 구현할 때는 Protect 메서드를 사용하여 문서를 보호합니다.

기본적으로 암호로 보호된 문서의 캐시된 데이터에 대한 변경 사항은 문서가 저장될 때 유지되지 않습니다.캐시된 데이터의 변경 사항을 저장하려면 프로젝트에서 다음 메서드를 재정의해야 합니다.

  • UnprotectDocument.문서가 저장되면 Microsoft Visual Studio Tools for Office Runtime에서 이 메서드를 호출합니다.이 메서드에 문서의 보호를 임시로 해제하는 코드를 추가합니다.이를 통해 캐시된 데이터의 변경 사항을 저장할 수 있습니다.

  • ProtectDocument.문서가 저장된 후 Microsoft Visual Studio Tools for Office Runtime에서 이 메서드를 호출합니다.이 메서드에 문서에 보호를 다시 적용하는 코드를 추가합니다.

자세한 내용은 방법: 암호로 보호된 문서의 데이터 캐시을 참조하십시오.

암호 보호와 관련이 없는 오류로 인해 캐시된 데이터를 저장할 수 없는 경우에도 Microsoft Visual Studio Tools for Office Runtime에서는 ProtectDocument 메서드를 호출합니다.예를 들어 ICachedType 인터페이스를 구현하여 캐시된 데이터가 문서에 저장되는 방식을 사용자 지정하는 경우, ICachedType 구현에서 캐시된 데이터를 저장할 수 없게 하는 예외가 throw되더라도 ProtectDocument 메서드가 호출됩니다.

예제

다음 코드 예제에서는 ProtectDocument 메서드를 재정의하여 UnprotectDocument 메서드 재정의를 통해 해제된 보호를 다시 적용하는 방법을 보여 줍니다.이 코드에서는 암호가 securelyStoredPassword라는 필드에 저장되어 있다고 가정합니다.이 예제를 사용하려면 문서 수준 프로젝트 ThisDocument 클래스에서 실행하십시오.

<CachedAttribute()> _
Public CachedString As String = "This string is cached in the document."

Private protectionTypeValue As Word.WdProtectionType

Protected Overrides Sub UnprotectDocument()
    If Me.ProtectionType <> Word.WdProtectionType.wdNoProtection Then
        protectionTypeValue = Me.ProtectionType
        Me.Unprotect(securelyStoredPassword)
    End If
End Sub

Protected Overrides Sub ProtectDocument()
    Me.Protect(protectionTypeValue, password:=securelyStoredPassword)
End Sub
[CachedAttribute]
public string CachedString = "This string is cached in the document.";

private Word.WdProtectionType protectionTypeValue;

protected override void UnprotectDocument()
{
    if (this.ProtectionType != Word.WdProtectionType.wdNoProtection)
    {
        protectionTypeValue = this.ProtectionType;
        this.Unprotect(ref securelyStoredPassword);
    }
}

protected override void ProtectDocument()
{
    this.Protect(protectionTypeValue, ref missing,
        ref securelyStoredPassword, ref missing, ref missing);
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

DocumentBase 클래스

Microsoft.Office.Tools.Word 네임스페이스

UnprotectDocument

기타 리소스

데이터 캐싱

방법: 암호로 보호된 문서의 데이터 캐시