RedactionPolicy Class
Represents a sanitization policy, containing a set of specific redactions to apply.
Inheritance Hierarchy
SystemObject
  GroupDocs.RedactionRedactionPolicy

Namespace: GroupDocs.Redaction
Assembly: GroupDocs.Redaction (in GroupDocs.Redaction.dll) Version: 22.8
Syntax
public class RedactionPolicy

The RedactionPolicy type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyRedactions
Gets an array of fully configured Redaction-derived classes.
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodStatic memberCode exampleLoad(Stream)
Loads an instance of RedactionPolicy from a stream.
Public methodStatic memberCode exampleLoad(String)
Loads an instance of RedactionPolicy from a file path.
Protected methodMemberwiseClone (Inherited from Object.)
Public methodSave(Stream)
Saves the redaction policy to a stream.
Public methodSave(String)
Saves the redaction policy to a file.
Public methodToString (Inherited from Object.)
Remarks
Learn more
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.

C#
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 });
            }        
     }
}

The following example contains a sample XML policy file with sample configurations for all types of redactions.

<?xml version="1.0" encoding="utf-8"?>  
<redactionPolicy xmlns="http://www.groupdocs.com/redaction" >
  <regexRedaction regularExpression="(dolor)" actionType="ReplaceString" replacement="foobar" />  
  <exactPhraseRedaction searchPhrase="dolor" caseSensitive="true" actionType="DrawBox" color="Red" />   

  <cellColumnRedaction regularExpression="(foo)bar1" replacement="[red1]" columnIndex="1" worksheetIndex="2" /> 
  <cellColumnRedaction regularExpression="(foo)bar2" replacement="[red2]" wokrsheetName="Sample" /> 

  <eraseMetadataRedaction filter="All" />
  <metadataSearchRedaction filter="Title, Author" replacement="foobar" valueExpression="(metasearch)" keyExpression="" />  

 <annotationRedaction regularExpression="(anno1)" replacement="foobar" />  
 <deleteAnnotationRedaction regularExpression="(anno2)" />

 <imageAreaRedaction pointX="15" pointY="17" width="200" height="10" color="#AA50FC"  />  
 <imageAreaRedaction pointX="110" pointY="120" width="60" height="20" color="Magenta"  />  
</redactionPolicy>
See Also