Apply

Apply(Redaction)

Applies a redaction to the document.

public RedactorChangeLog Apply(Redaction redaction)
Parameter Type Description
redaction Redaction An instance of Redaction to apply

Return Value

Success or failure and error message in this case

Examples

The following example demonstrates applying a single redaction to the document.

using (Redactor redactor = new Redactor(@"D:\\test.docx"))
{
   RedactorChangeLog result = redactor.Apply(new RegexRedaction(LookupStrings.SSNRegexPattern, new ReplacementOptions("[ssn]")));
   if (result.Status != RedactionStatus.Failed)
   {
      redactor.Save();
   };
}

See Also


Apply(Redaction[])

Applies a set of redactions to the document.

public RedactorChangeLog Apply(Redaction[] redactions)
Parameter Type Description
redactions Redaction[] An array of redactions to apply

Return Value

Success or failure and error message in this case

Examples

The following example demonstrates applying a list of redactions to the document.

using (Redactor redactor = new Redactor(@"D:\\test.docx"))
{
   var redactionList = new Redaction[] 
   {
      new ExactPhraseRedaction(LookupStrings.ClientName, new ReplacementOptions("[client]")),
      new ExactPhraseRedaction(LookupStrings.ClientAddress, new ReplacementOptions(System.Drawing.Color.Red)),
      new RegexRedaction(LookupStrings.SSNRegexPattern, new ReplacementOptions("[ssn]")),
      new RegexRedaction(LookupStrings.BankCardRegexPattern, new ReplacementOptions(System.Drawing.Color.Blue)),
      // ... other redactions
      new DeleteAnnotationRedaction("(?im:(use|show|describe))"),
      new EraseMetadataRedaction(MetadataFilter.Author),
      new MetadataSearchRedaction(LookupStrings.CompanyName, "--company--") 
   }; 
   RedactorChangeLog result = redactor.Apply(redactionList);
   // false, if at least one redaction failed
   if (result.Status != RedactionStatus.Failed)
   {
      redactor.Save();
   };
}

See Also


Apply(RedactionPolicy)

Applies a redaction policy to the document.

public RedactorChangeLog Apply(RedactionPolicy policy)
Parameter Type Description
policy RedactionPolicy Redaction policy

Return Value

Success or failure and error message in this case

Examples

The following example demonstrates how to apply a redaction policy to all files within a given inbound folder, and save to one of outbound folders - for successfully updated files and for failed ones.

RedactionPolicy policy = RedactionPolicy.Load("RedactionPolicy.xml");
foreach (var fileEntry in Directory.GetFileNames("C:\\Inbound")) 
{
     using (Redactor redactor = new Redactor(Path.Combine("C:\\Inbound\\", fileEntry)))
     {
    	     RedactorChangeLog result = redactor.Apply(policy);
    	     String resultFolder = result.Status != RedactionStatus.Failed ? "C:\\Outbound\\Done\\" : "C:\\Outbound\\Failed\\";
    	     using (Stream fileStream = File.Open(Path.Combine(resultFolder, fileEntry), FileMode.Open, FileAccess.ReadWrite))
   	     {
               redactor.Save(fileStream, new RasterizationOptions() { Enabled = false });
   	     }        
     }
}   

See Also