We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Instead of Pink, Protected Word Document shows Editable Range in Yellow Color | C# .NET

Hi,

I want to create document with editable range. When I create document from your code (https://apireference.aspose.com/words/net/aspose.words/documentbuilder/methods/starteditablerange) I have document with yellow field. In more complicated code I have document with pink field. Is any option to change color in editable range?
When I try to found solution I saw document cannot be correctly created when I call Save before EndEditableRange. See the sample program:

var doc = new Document();
doc.Protect(ProtectionType.ReadOnly, "MyPassword");
var builder = new DocumentBuilder(doc);
builder.StartEditableRange();
builder.Writeln("This paragraph can be edited.");
doc.Save("DocumentBeforeEnd.docx");
builder.EndEditableRange();
doc.Save("DocumentAfterEnd.docx");

Document DocumentAfterEnd should be created without editable range?

Thanks,
Monika

@acturisaspose,

We have logged the following problems in our issue tracking system.

WORDSNET-22720: Provide API to Change Color of Editable Range
WORDSNET-22721: EditableRange doesn’t work when document is saved before end

We will further look into the details of these problems and will keep you updated here on the statuses of these issues. We apologize for your inconvenience.

@acturisaspose Yes, DocumentAfterEnd should be created without editable range. When you call Document.Save method the first time, model validation is performed, and it detects editable range start without a corresponding end. This is an error and such orphan start is removed. If you add warning callback, like shown in the following example:

[Test]
public void Test001()
{
    var doc = new Document();
    doc.WarningCallback = new WarningCallback();
    doc.Protect(ProtectionType.ReadOnly, "MyPassword");
    var builder = new DocumentBuilder(doc);
    builder.StartEditableRange();
    builder.Writeln("This paragraph can be edited.");
    doc.Save("DocumentBeforeEnd.docx");
    builder.EndEditableRange();
    doc.Save("DocumentAfterEnd.docx");
}

class WarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        Console.WriteLine(info.Description);
    }
}

You will see the following warning:
EditableRangeStart without corresponding EditableRangeEnd was removed.

So I close WORDSNET-22721 as Not a Bug.

@acturisaspose Could you please attach the document with pink fields? We will check it and provide you more information.

Thank you for explain why document is saved in another way than I expected!

This is document with pink field:
Pink-field.docx (7.4 KB)

Thanks,
Monika

@acturisaspose Thank you for additional information. I am afraid I should close WORDSNET-22720 as Not a Bug too. Editable range highlighting is not stored in the document and cannot be controlled by Aspose.Words. Also, MS Word highlights editable range with yellow color if document is protected, and with pink when document is not protected. See the following code for example:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("This paragraph cannot be edited.");
builder.StartEditableRange();
builder.Write("This paragraph can be edited.");
builder.EndEditableRange();
builder.Writeln();
builder.Writeln("This paragraph cannot be edited.");
// Editable range will be highlighted with pink.
doc.Save(@"C:\Temp\NotProtected.docx");
doc.Protect(ProtectionType.ReadOnly, "MyPassword");
// Editable range will be highlighted with yellow.
doc.Save(@"C:\Temp\Protected.docx");