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


C# Document.Protect方法代码示例

本文整理汇总了C#中Aspose.Words.Document.Protect方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Protect方法的具体用法?C# Document.Protect怎么用?C# Document.Protect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Aspose.Words.Document的用法示例。


在下文中一共展示了Document.Protect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Protect

        public void Protect()
        {
            //ExStart
            //ExFor:Document.Protect(ProtectionType)
            //ExFor:ProtectionType
            //ExFor:Section.ProtectedForForms
            //ExSummary:Protects a section so only editing in form fields is possible.
            // Create a blank document
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Insert two sections with some text
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.Writeln("Section 1. Unprotected.");
            builder.InsertBreak(BreakType.SectionBreakContinuous);
            builder.Writeln("Section 2. Protected.");

            // Section protection only works when document protection is turned and only editing in form fields is allowed.
            doc.Protect(ProtectionType.AllowOnlyFormFields);

            // By default, all sections are protected, but we can selectively turn protection off.
            doc.Sections[0].ProtectedForForms = false;

            builder.Document.Save(ExDir + "Section.Protect Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:25,代码来源:ExSection.cs

示例3: PrintWordEx

 public static void PrintWordEx(string targetFile, byte[] docBytes, DataSet dataSource, bool preview, PrintBySelf printByself, FormatColumnValue formatColumnValue, bool write)
 {
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += delegate (object sender, DoWorkEventArgs e) {
         WaitDialogHelper.Show();
         try
         {
             using (MemoryStream stream = new MemoryStream(docBytes))
             {
                 if (license == null)
                 {
                     license = new Aspose.Words.License();
                     license.SetLicense("Aspose.lic");
                 }
                 Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                 InternalWrodReportExecute(doc, dataSource, printByself, formatColumnValue);
                 if (!write)
                 {
                     doc.Protect(ProtectionType.ReadOnly, "sbdwlfty");
                 }
                 if (preview)
                 {
                     doc.Save(targetFile);
                     Process.Start(targetFile);
                 }
                 else
                 {
                     new AsposeWordsPrintDocument(doc).Print();
                 }
             }
         }
         finally
         {
             WaitDialogHelper.Close();
         }
     };
     worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(PrintHelper.RunPrintWordWorkerCompleted);
     worker.RunWorkerAsync();
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:39,代码来源:PrintHelper.cs

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