DocumentCleanup Method
Cleans unused styles and lists from the document.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
Syntax
public void Cleanup()
Examples
Shows how to remove unused styles and lists from a document.
[C#]

// Create a new document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Brand new documents have 4 styles and 0 lists by default
Assert.AreEqual(4, doc.Styles.Count);
Assert.AreEqual(0, doc.Lists.Count);

// We will add one style and one list and mark them as "used" by applying them to the builder 
builder.ParagraphFormat.Style = doc.Styles.Add(StyleType.Paragraph, "My Used Style");
builder.ListFormat.List = doc.Lists.Add(ListTemplate.BulletDiamonds);

// These items were added to their respective collections
Assert.AreEqual(5, doc.Styles.Count);
Assert.AreEqual(1, doc.Lists.Count);

// doc.Cleanup() removes all unused styles and lists
doc.Cleanup();

// It currently has no effect because the 2 items we added plus the original 4 styles are all used
Assert.AreEqual(5, doc.Styles.Count);
Assert.AreEqual(1, doc.Lists.Count);

// These two items will be added but will not associated with any part of the document
doc.Styles.Add(StyleType.Paragraph, "My Unused Style");
doc.Lists.Add(ListTemplate.NumberArabicDot);

// They also get stored in the document and are ready to be used
Assert.AreEqual(6, doc.Styles.Count);
Assert.AreEqual(2, doc.Lists.Count);

doc.Cleanup();

// Since we didn't apply them anywhere, the two unused items are removed by doc.Cleanup()
Assert.AreEqual(5, doc.Styles.Count);
Assert.AreEqual(1, doc.Lists.Count);
See Also