本文整理汇总了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
}
示例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
}
示例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);
}
示例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);
}
示例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
}
示例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();
}
示例7: Main
static void Main(string[] args)
{
Document doc = new Document();
doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
}