DocumentBase.Unprotect 方法

移除文件的保護。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
Public Sub Unprotect ( _
    ByRef password As Object _
)
public void Unprotect(
    ref Object password
)

參數

  • password
    型別:System.Object%
    用來保護文件的密碼。密碼要區分大小寫。如果有使用密碼保護文件,而且尚未提供正確密碼,則會出現對話方塊提示使用者輸入密碼。

備註

避免在您的應用程式中使用固定編碼密碼。 如果程序中需要密碼,請向使用者要求密碼,並將密碼儲存在變數中,再將變數用於程式碼中。

如果該文件不被保護,就會擲回例外狀況。

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例會使用 Unprotect 方法移除文件的保護。 範例假設已從使用者的輸入取得密碼變數 securelyStoredPassword。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

Private Sub DocumentUnprotect(ByRef securelyStoredPassword As Object)
    If Me.ProtectionType <> Word.WdProtectionType.wdNoProtection Then
        Me.Unprotect(securelyStoredPassword)
    End If
End Sub
private void DocumentUnprotect(ref object securelyStoredPassword)
{
    if (this.ProtectionType != Word.WdProtectionType.wdNoProtection)
    {
        this.Unprotect(ref securelyStoredPassword);
    }
}

.NET Framework 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間