A configuration file defines the initial or commonly used parameters, options, settings or preferences applied to operating systems, infrastructure devices or applications in an IT context.
When the Need Arises
If you have large size data (may consist of multiple files of different file formats) or corporate sensitive data which need to be redacted without specifying the rules in your code.
What is the Solution
The GroupDocs.Redaction API provides the way to define a removal policy by writing the list of pre-configured redaction rules in an XML file. Hence, you do not need to specify the rules in your code. You can have as many policies, as you need to redact your documents.
The example of redaction policy XML file is as follows:
<?xml version="1.0" encoding="utf-8"?> | |
<redactionPolicy xmlns="http://www.groupdocs.com/redaction"> | |
<regexRedaction regularExpression="(John)" actionType="ReplaceString" replacement="foobar" /> | |
<exactPhraseRedaction searchPhrase="foobar" caseSensitive="true" actionType="DrawBox" color="Red" /> | |
<cellColumnRedaction regularExpression="^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$" replacement="[red1]" columnIndex="1" worksheetIndex="2" /> | |
<cellColumnRedaction searchPhrase="John" replacement="[red2]" wokrsheetName="Sheet1" /> | |
<eraseMetadataRedaction filter="All" /> | |
<metadataSearchRedaction filter="Title, Author" replacement="foobar" valueExpression="(metasearch)" keyExpression="" /> | |
<annotationRedaction regularExpression="(Zara)" replacement="bar" /> | |
<deleteAnnotationRedaction regularExpression="(bar)" /> | |
<imageAreaRedaction pointX="15" pointY="400" width="1200" height="10" color="#AA50FC" /> | |
<imageAreaRedaction pointX="110" pointY="120" width="360" height="200" color="Magenta" /> | |
</redactionPolicy> |
How to Apply Redaction Policy
The example below shows:
- how to apply the redaction policy to all files by giving inbound folder
- Save the output files to one of outbound folders
- The successfully updated files and failed one will save to their respected folders
- The current date and time is used as a part of output file name
- The successfully updated files and failed one will save to their respected folders
// For complete examples and data files, please go to https://github.com/groupdocs-redaction/GroupDocs.Redaction-for-.NET | |
//Initialize RedactionPolicy | |
RedactionPolicy policy = RedactionPolicy.Load(Common.MapSourceFilePath("Documents/Bulk/RedactionPolicy.xml")); | |
foreach (var fileEntry in Directory.GetFiles(Common.MapSourceFilePath(Inbound_Path))) | |
{ | |
using (Document doc = Redactor.Load( fileEntry)) | |
{ | |
//Apply redaction | |
RedactionSummary result = doc.RedactWith(policy.Redactions); | |
// Set output directory path | |
String resultFolder = result.Status != RedactionStatus.Failed ? Common.MapSourceFilePath(Outbound_Done_Path) : Common.MapSourceFilePath(Outbound_Failed_Path); | |
// Save the ouput files after applying redactions | |
using (Stream fileStream = File.Create(Path.Combine(resultFolder, Path.GetFileName(fileEntry)))) | |
{ | |
doc.Save(fileStream, new SaveOptions() { RasterizeToPDF = false, RedactedFileSuffix = DateTime.Now.ToString() }); | |
fileStream.Close(); | |
} | |
} | |
} |
The complete ready to run code sample is available on GitHub.