I know there are several docx creation/modification approaches in C#
OpenXML, DocX API, etc.
I've figured out how to enable tracked changes using Open XML, just haven't figured out to lock the tracked changes (a feature in word 2013).
I know there are several docx creation/modification approaches in C#
OpenXML, DocX API, etc.
I've figured out how to enable tracked changes using Open XML, just haven't figured out to lock the tracked changes (a feature in word 2013).
This code works fine for me:
static void Main(string[] args)
{
using (var document = WordprocessingDocument.Open(@"D:\DocTest\Test1.docx", true))
{
AddTrackingLock(document);
}
}
private static void AddTrackingLock(WordprocessingDocument document)
{
var documentSettings = document.MainDocumentPart.DocumentSettingsPart;
var documentProtection = documentSettings
.Settings
.FirstOrDefault(it =>
it is DocumentProtection &&
(it as DocumentProtection).Edit == DocumentProtectionValues.TrackedChanges)
as DocumentProtection;
if (documentProtection == null)
{
var documentProtectionElement = new DocumentProtection();
documentProtectionElement.Edit = DocumentProtectionValues.TrackedChanges;
documentProtectionElement.Enforcement = OnOffValue.FromBoolean(true);
documentSettings.Settings.AppendChild(documentProtectionElement);
}
else
{
documentProtection.Enforcement = OnOffValue.FromBoolean(true);
}
}
Have a look at How to set the editing restrictions in Word using Open XML SDK 2.0
I don't have any working code for you, but the password hash needs to be stored in
DocumentProtection.Hash
.
Hope that this hint helps moving you along!