本文整理汇总了C#中Aspose.Words.Document.Unprotect方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Unprotect方法的具体用法?C# Document.Unprotect怎么用?C# Document.Unprotect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aspose.Words.Document
的用法示例。
在下文中一共展示了Document.Unprotect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProtectUnprotectDocument
public void ProtectUnprotectDocument()
{
//ExStart
//ExFor:Document.Protect(ProtectionType,String)
//ExId:ProtectDocument
//ExSummary:Shows how to protect a document.
Aspose.Words.Document doc = new Aspose.Words.Document();
doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
//ExEnd
//ExStart
//ExFor:Document.Unprotect
//ExId:UnprotectDocument
//ExSummary:Shows how to unprotect a document. Note that the password is not required.
doc.Unprotect();
//ExEnd
//ExStart
//ExFor:Document.Unprotect(String)
//ExSummary:Shows how to unprotect a document using a password.
doc.Unprotect("password");
//ExEnd
}
示例2: BTN_Clean_Click
private void BTN_Clean_Click(object sender, EventArgs e)
{
int cleanedCount = 0;
bool passwordFlg = false;
bool errorFlg = false;
string Message = "";
foreach (string ThisFile in InputFiles)
{
AsposeWords.FileFormatInfo info = AsposeWords.FileFormatUtil.DetectFileFormat(ThisFile);
bool WordAttachment = false;
switch (info.LoadFormat)
{
case AsposeWords.LoadFormat.Doc:
case AsposeWords.LoadFormat.Dot:
case AsposeWords.LoadFormat.Docx:
case AsposeWords.LoadFormat.Docm:
case AsposeWords.LoadFormat.Dotx:
case AsposeWords.LoadFormat.Dotm:
case AsposeWords.LoadFormat.FlatOpc:
case AsposeWords.LoadFormat.Rtf:
case AsposeWords.LoadFormat.WordML:
case AsposeWords.LoadFormat.Html:
case AsposeWords.LoadFormat.Mhtml:
case AsposeWords.LoadFormat.Odt:
case AsposeWords.LoadFormat.Ott:
case AsposeWords.LoadFormat.DocPreWord97:
WordAttachment = true;
break;
default:
WordAttachment = false;
break;
}
// If word Attachment is found
if (WordAttachment)
{
try
{
AsposeWords.Document doc = new AsposeWords.Document(ThisFile);
// Remove if there is any protection on the document
AsposeWords.ProtectionType protection = doc.ProtectionType;
if (protection != AsposeWords.ProtectionType.NoProtection)
doc.Unprotect();
// Remove all built-in and Custom Properties
doc.CustomDocumentProperties.Clear();
doc.BuiltInDocumentProperties.Clear();
// Password will be removed if the document is password protected.
if (protection != AsposeWords.ProtectionType.NoProtection)
doc.Protect(protection);
// Save the file back to temp location
doc.Save(ThisFile);
cleanedCount++;
}
catch (Words.IncorrectPasswordException)
{
passwordFlg = true;
Message = "Password protected files cannot be cleaned";
}
catch (Exception ex)
{
errorFlg = true;
Message = "Error: " + ex.Message;
}
}
else
Message = "Not a Word Document";
}
if (passwordFlg)
LBL_Error.Text = Message;
if (errorFlg)
LBL_Error.Text = Message;
BTN_Clean.Enabled = false;
LBL_Cleaned.Text = cleanedCount.ToString();
}