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


C# Document.Protect方法代码示例

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


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

示例1: 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
            Document doc = new 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(MyDir + @"\Artifacts\Section.Protect.doc");
            //ExEnd
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:25,代码来源:ExSection.cs

示例2: Protect

 /// <summary>
 /// Shows how to protect document
 /// </summary>
 /// <param name="inputFileName">input file name with complete path.</param>        
 public static void Protect(string inputFileName)
 {
     //ExStart:ProtectDocument
     Document doc = new Document(inputFileName);
     doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
     Console.WriteLine("\nDocument protected successfully.");
     //ExEnd:ProtectDocument
 }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:12,代码来源:ProtectDocument.cs

示例3: Main

        static void Main(string[] args)
        {
            Document doc = new Document("../../data/document.doc");
            doc.Protect(ProtectionType.ReadOnly);

            // Following other Protection types are also available
            // ProtectionType.NoProtection
            // ProtectionType.AllowOnlyRevisions
            // ProtectionType.AllowOnlyComments
            // ProtectionType.AllowOnlyFormFields

            doc.Save("AsposeProtect.doc", SaveFormat.Doc);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:13,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            // Check for license and apply if exists
            string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
            if (File.Exists(licenseFile))
            {
                // Apply Aspose.Words API License
                Aspose.Words.License license = new Aspose.Words.License();
                // Place license file in Bin/Debug/ Folder
                license.SetLicense("Aspose.Words.lic");
            }

            Document doc = new Document("../../data/document.doc");
            doc.Protect(ProtectionType.ReadOnly);

            // Following other Protection types are also available
            // ProtectionType.NoProtection
            // ProtectionType.AllowOnlyRevisions
            // ProtectionType.AllowOnlyComments
            // ProtectionType.AllowOnlyFormFields

            doc.Save("AsposeProtect.doc", SaveFormat.Doc);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:23,代码来源:Program.cs

示例5: ProtectUnprotectDocument

        public void ProtectUnprotectDocument()
        {
            //ExStart
            //ExFor:Document.Protect(ProtectionType,String)
            //ExId:ProtectDocument
            //ExSummary:Shows how to protect a document.
            Document doc = new Document();
            doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
            //ExEnd

            //ExStart
            //ExFor:Document.Unprotect
            //ExId:UnprotectDocument
            //ExSummary:Shows how to unprotect any document. Note that the password is not required.
            doc.Unprotect();
            //ExEnd
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:17,代码来源:ExDocument.cs

示例6: GenerateDoc


//.........这里部分代码省略.........
            try
            {
                doc.UpdateFields();
                doc.Range.UpdateFields();
            }
            catch (Exception)
            {
                // Error sometimes occurrs in Aspose when calling UpdateFields.
            }

            NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

            foreach (Paragraph para in paragraphs)
            {
                if (para.IsListItem)
                {
                    foreach (Node node in para.ChildNodes)
                    {
                        Run run = node as Run;

                        if (run != null)
                        {
                            bool runBeginsWithATab = run.Range.Text.Count() > 0 && run.Range.Text[0] == '\t';

                            if (runBeginsWithATab)
                            {
                                run.Text = run.Range.Text.Remove(0, 1);
                            }
                        }
                    }
                }
            }

            MemoryStream stream = new MemoryStream();
            doc.BuiltInDocumentProperties.LastSavedTime = DateTime.UtcNow;
            try
            {
                doc.UpdateFields();
            }
            catch (Exception)
            {
                // Error sometimes occurrs in Aspose when calling UpdateFields.
            }
            doc.AcceptAllRevisions();

            if (configData.IsCIP)
            {
                if (configData.BodyTemplate != null)
                {
                    MemoryStream newStream2 = null;
                    if (configData.BodyTemplate != null)
                    {
                        using (newStream2 = new MemoryStream(configData.BodyTemplate))
                        {
                            Document bodyDoc = new Document(newStream2);
                            InsertDocumentAtBookmark(Bookmarks.BPLUS_BODY, doc, bodyDoc);
                        }
                    }
                }
                else
                {
                    if (doc.Range.Bookmarks[Bookmarks.BPLUS_BODY] != null)
                    {
                        doc.Range.Bookmarks[Bookmarks.BPLUS_BODY].Text = "";
                    }
                }

            }

            try
            {
                if (configData.LockDocument)
                {
                    doc.Protect(ProtectionType.ReadOnly);
                }

                if (configData.IsGenerateTaskDocument && doc.ProtectionType == ProtectionType.AllowOnlyFormFields)
                {
                    doc.Unprotect();
                    doc.Protect(ProtectionType.AllowOnlyFormFields, "BOA1234");
                }

                // Save the document to the memory stream.
                switch (configData.Format)
                {
                    case "pdf":
                        doc.Save(stream, SaveFormat.Pdf);
                        break;
                    default:
                        doc.Save(stream, SaveFormat.Doc);
                        break;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return stream.ToArray();
        }
开发者ID:khangtran-steadfast,项目名称:DatabaseConversion,代码行数:101,代码来源:WordGenerator.cs

示例7: Main

 static void Main(string[] args)
 {
     Document doc = new Document();
     doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
 }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:5,代码来源:Program.cs


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