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

How to clear out all content in a document?

I am trying to find a way in Aspose.Words to clear out all “content” (text, tables, images, bookmarks, etc) from a document, and also preserve the styles at the same time? The idea is to copy a document, keep the basic document template, but blow away all of its content. My best stab at this so far has been the following:

Aspose.Words.Document newDocument = sourceDocument.Clone();
newDocument.RemoveAllChildren();
newDocument.RemoveMacros();
newDocument.Range.Bookmarks.Clear();


I know that Document.RemoveMacros() does the macro part of this, and Document.Range.Bookmarks.Clear() takes care of the bookmarks, but the remainder of the content is where I’m getting stuck.
Any ideas?
Thanks!

Hi
Thanks for your request. If you just need to remove all content from the document, it is enough to use the following code:

Document doc = new Document(@"Test161\in.doc");
doc.RemoveAllChildren();
doc.EnsureMinimum();
doc.Save(@"Test161\out.doc");


Hope this helps.
Best regards.

That did the trick. Thanks!!