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

Free Support Forum - aspose.com

Cannot reset the protection with ProtectionType.AllowOnlyRevisions

I need to clear the document in two steps:

1. Accept all revisions;
2. Clear all styles, colors and other with changing the color of the text and the background.

But when I compile following code, protection is still on.

var doc = new Document(File.ContentFilePath);
Console.WriteLine(doc.ProtectionType.ToString()); //AllowOnlyRevisions
doc.Unprotect("1");
doc.AcceptAllRevisions();
doc.Save(File.ContentFilePath);
Attachments:
1. Sample.docx - original.
  1. SampleAfter.docx - after compilling.

Thanks.

Hi there,


Thanks for your inquiry. Your both documents are same. You can accept all revision and remove the paragraph and run node formatting using following code example. Hope this helps you.

If you still face problem, please share your expected output document here for our reference. We will then provide you more information about your query along with code.

Document doc = new Document(MyDir + “Sample.docx”);<o:p></o:p>

Console.WriteLine(doc.ProtectionType.ToString()); //AllowOnlyRevisions

doc.Unprotect("1");

doc.AcceptAllRevisions();

doc.StopTrackRevisions();

doc.TrackRevisions = false;

//If you want to clear font formatting of document,

//please use following code snippet

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

{

para.ParagraphFormat.ClearFormatting();

foreach (Run run in para.Runs)

{

run.Font.ClearFormatting();

}

}

//Remove the background color of table's cells

foreach (Cell cell in doc.GetChildNodes(NodeType.Cell, true))

{

cell.CellFormat.Shading.ClearFormatting();

}

doc.Save(MyDir + "Out 17.2.0.docx");

How can I do it without this method: doc.AcceptAllRevisions();

Because I use version 14… and I don’t have an opportunity to update it to 17… in short period (before my project ends).

Thank you a lot!

Attachment contains “right” document after cleaning and accepting revisions.

Hi there,

Thanks for your inquiry. Unfortunately, we don't provide support for older releases of Aspose.Words. Please note that we do not provide any fixes or patches for old versions of Aspose products either. All fixes and new features are always added into new versions of our products. So, you will have to upgrade if you need new features or fixes. Please use latest version of Aspose.Words for .NET 17.2.0.

Please use following code example to achieve your requirements.

// Open the document.

Document doc = new Document(MyDir + "Sample .docx");

doc.Unprotect("1");

doc.AcceptAllRevisions();

doc.StopTrackRevisions();

doc.TrackRevisions = false;

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

{

foreach (Run run in para.Runs)

{

run.Font.Shading.ClearFormatting();

}

}

//Remove the background color of table's cells

foreach (Cell cell in doc.GetChildNodes(NodeType.Cell, true))

{

cell.CellFormat.Shading.ClearFormatting();

}

doc.Save(MyDir + "Out 17.2.0.docx");

Thanks for your help. But this following code only can accept all the revisions (hide the wipe text). But he doesn’t even color the background color and didn’t clear the formatting of the document. He just can’t unprotect the document (password: 1). I set the protection with the “Track Changes”.


Here is my code. File in attachment

Document doc = new Document(fl.File.ContentFilePath);

Attachment att = new Attachment();
att.File = context.Attachment.File;
att.Save();

Console.WriteLine(doc.ProtectionType.ToString()); //AllowOnlyRevisions
doc.Unprotect(“1”);
doc.AcceptAllRevisions();
doc.TrackRevisions = false;

foreach(Cell cell in doc.GetChildNodes(NodeType.Cell, true))
{
cell.CellFormat.Shading.ClearFormatting();
cell.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.Empty;
}

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
para.ParagraphFormat.ClearFormatting();
para.ParagraphFormat.Shading.BackgroundPatternColor = System.Drawing.Color.Empty;
foreach (Run run in para.Runs)
{
run.Font.ClearFormatting();
run.Font.Shading.BackgroundPatternColor = System.Drawing.Color.Empty;
}
}
doc.Save(fl.File.ContentFilePath);



I use MS Word 2013.
Hi there,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for .NET 17.2.0 with following code example and have not found the shared issue. Please use Aspose.Words for .NET 17.2.0. We have attached the output document with this post for your kind reference.

If you still face problem, please share your output and expected output documents here for our reference. We will then provide you more information about your query.

// Open the document.

Document doc = new Document(MyDir + "Sample (8).docx");

doc.Unprotect("1");

doc.AcceptAllRevisions();

doc.StopTrackRevisions();

doc.TrackRevisions = false;

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))

{

//para.ParagraphFormat.ClearFormatting();

para.ParagraphFormat.Shading.ClearFormatting();

foreach (Run run in para.Runs)

{

run.Font.ClearFormatting();

//run.Font.Shading.BackgroundPatternColor = System.Drawing.Color.Empty;

}

}

//Remove the background color of table's cells

foreach (Cell cell in doc.GetChildNodes(NodeType.Cell, true))

{

cell.CellFormat.Shading.ClearFormatting();

//cell.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.Empty;

}

doc.Save(MyDir + "Out 17.2.0.docx");