Share via


DocumentBase.UnprotectDocument 메서드

문서에서 암호 보호를 제거하고 캐시된 데이터가 저장되도록 설정할 수 있는 옵션을 제공합니다.

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

구문

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

설명

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

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

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

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

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

예제

다음 코드 예제에서는 캐시된 데이터의 변경 사항을 저장할 수 있도록 UnprotectDocument 메서드를 재정의하여 문서의 보호를 임시로 해제하는 방법을 보여 줍니다. 이 예제에서는 먼저 현재 ProtectionType 값을 저장하므로 나중에 ProtectDocument 메서드에서 동일한 형식의 보호를 다시 적용할 수 있습니다. 이 코드에서는 암호가 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 네임스페이스

ProtectDocument

기타 리소스

데이터 캐싱

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