当前位置: 首页>>代码示例>>C#>>正文


C# Document.Unprotect方法代码示例

本文整理汇总了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
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:23,代码来源:ExDocument.cs

示例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();
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:79,代码来源:MetadataCleaner.cs


注:本文中的Aspose.Words.Document.Unprotect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。