Document

Overview

Document is a class in Aspose.Words FOSS for .NET. Inherits from: DocumentBase, ISectionAttrSource, IWatermarkProvider.

The Document class constructors let developers create a new empty document or load an existing one from a file path, stream, or with custom load options.

This class provides 63 methods for working with Document objects in .NET programs. Available methods include: Accept, AcceptAllRevisions, AcceptEnd, AcceptStart, AppendChild, AppendDocument, Cleanup, Clone, CopyStylesFromTemplate, CreateNavigator, Document, EnsureMinimum, and 36 additional methods. All public members are accessible to any .NET application after installing the Aspose.Words FOSS for .NET package. Properties: AttachedTemplate, AutomaticallyUpdateStyles, BackgroundShape, Bibliography, BuiltInDocumentProperties, CompatibilityOptions, and 62 more.

Properties

NameTypeAccessDescription
AttachedTemplatestringRead/WriteGets or sets the full path of the template attached to the document.
AutomaticallyUpdateStylesboolRead/WriteGets or sets a flag indicating whether the styles in the document are updated to match the styles in the attached template each time the document is opened in MS Word.
ShadeFormDataboolRead/WriteSpecifies whether to turn on the gray shading on form fields.
TrackRevisionsboolRead/WriteTrue if changes are tracked when this document is edited in Microsoft Word.
ShowGrammaticalErrorsboolRead/WriteSpecifies whether to display grammar errors in this document.
ShowSpellingErrorsboolRead/WriteSpecifies whether to display spelling errors in this document.
SpellingCheckedboolRead/WriteReturns true if the document has been checked for spelling.
GrammarCheckedboolRead/WriteReturns true if the document has been checked for grammar.
PunctuationKerningboolRead/WriteSpecifies whether kerning applies to both Latin text and punctuation.
NodeTypeNodeTypeReadReturns Document.
BuiltInDocumentPropertiesBuiltInDocumentPropertiesReadReturns a collection that represents all the built-in document properties of the document.
WebExtensionTaskPanesTaskPaneCollectionReadReturns a collection that represents a list of task pane add-ins.
CustomDocumentPropertiesCustomDocumentPropertiesReadReturns a collection that represents all the custom document properties of the document.
ProtectionTypeProtectionTypeReadGets the currently active document protection type.
SectionsSectionCollectionReadReturns a collection that represents all sections in the document.
FirstSectionSectionReadGets the first section in the document.
LastSectionSectionReadGets the last section in the document.
ViewOptionsViewOptionsReadProvides options to control how the document is displayed in Microsoft Word.
WriteProtectionWriteProtectionReadProvides access to the document write protection options.
CompatibilityOptionsCompatibilityOptionsReadProvides access to document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word).
MailMergeSettingsMailMergeSettingsRead/WriteGets or sets the object that contains all of the mail merge information for a document.
HyphenationOptionsHyphenationOptionsReadProvides access to document hyphenation options.
HasRevisionsboolReadReturns true if the document has any tracked changes.
HasMacrosboolReadReturns true if the document has a VBA project (macros).
WatermarkWatermarkReadProvides access to the document watermark.
VersionsCountintReadGets the number of document versions that was stored in the DOC document.
DefaultTabStopdoubleRead/WriteGets or sets the interval (in points) between the default tab stops.
ThemeThemeReadGets the Theme object for this document.
CustomXmlPartsCustomXmlPartCollectionRead/WriteGets or sets the collection of Custom XML Data Storage Parts.
PackageCustomPartsCustomPartCollectionRead/WriteGets or sets the collection of custom parts (arbitrary content) that are linked to the OOXML package using “unknown relationships”.
VariablesVariableCollectionReadReturns the collection of variables added to a document or template.
GlossaryDocumentGlossaryDocumentRead/WriteGets or sets the glossary document within this document or template.
OriginalFileNamestringReadGets the original file name of the document.
OriginalLoadFormatLoadFormatReadGets the format of the original document that was loaded into this object.
ComplianceOoxmlComplianceReadGets the OOXML compliance version determined from the loaded document content.
DigitalSignaturesDigitalSignatureCollectionReadGets the collection of digital signatures for this document and their validation results.
FontSettingsFontSettingsRead/WriteGets or sets document font settings.
BibliographyBibliography.BibliographyReadGets the Bibliography object that represents the list of sources available in the document.
FramesetFramesetReadReturns a Frameset instance if this document represents a frames page.
IncludeTextboxesFootnotesEndnotesInStatboolRead/WriteSpecifies whether to include textboxes, footnotes and endnotes in word count statistics.
RevisionsRevisionCollectionReadGets a collection of revisions (tracked changes) that exist in this document.
RevisionsViewRevisionsViewRead/WriteGets or sets a value indicating whether to work with the original or revised version of a document.
JustificationModeJustificationModeRead/WriteGets or sets the character spacing adjustment of a document.
FootnoteOptionsFootnoteOptionsReadProvides options that control numbering and positioning of footnotes in this document.
EndnoteOptionsEndnoteOptionsReadProvides options that control numbering and positioning of endnotes in this document.
FieldOptionsFieldOptionsReadGets a FieldOptions object that represents options to control field handling in the document.
RemovePersonalInformationboolRead/WriteGets or sets a flag indicating that Microsoft Word will remove all user information from comments, revisions and document properties upon saving the document.
VbaProjectVbaProjectRead/WriteGets or sets a VbaProject.
DocumentDocumentBaseReadGets this instance.
NodeChangingCallbackINodeChangingCallbackRead/WriteCalled when a node is inserted or removed in the document.
ResourceLoadingCallbackIResourceLoadingCallbackRead/WriteAllows to control how external resources are loaded.
FontInfosFontInfoCollectionReadProvides access to properties of fonts used in this document.
StylesStyleCollectionReadReturns a collection of styles defined in the document.
ListsListCollectionReadProvides access to the list formatting used in the document.
WarningCallbackIWarningCallbackRead/WriteCalled during various document processing procedures when an issue is detected that might result in data or formatting fidelity loss.
FootnoteSeparatorsFootnoteSeparatorCollectionReadProvides access to the footnote/endnote separators defined in the document.
BackgroundShapeShapeRead/WriteGets or sets the background shape of the document.
PageColorColorRead/WriteGets or sets the page color of the document.
IsCompositeboolReadReturns true as this node can have child nodes.
HasChildNodesboolReadReturns true if this node has any child nodes.
FirstChildNodeReadGets the first child of the node.
LastChildNodeReadGets the last child of the node.
CountintReadGets the number of immediate children of this node.
ParentNodeCompositeNodeReadGets the immediate parent of this node.
PreviousSiblingNodeReadGets the node immediately preceding this node.
NextSiblingNodeReadGets the node immediately following this node.
RangeRangeReadReturns a Range object that represents the portion of a document that is contained in this node.
CustomNodeIdintRead/WriteSpecifies custom node identifier.

Methods

SignatureDescription
Document()Creates or loads a document.
Document(fileName: string)Opens an existing document from a file.
Document(fileName: string, loadOptions: LoadOptions)Opens an existing document from a file.
Document(stream: Stream)Calls Document(stream) on this Document instance.
Document(stream: Stream, loadOptions: LoadOptions)Calls Document(stream, loadOptions) on this Document instance.
Clone()Performs a deep copy of the Document.
Accept(visitor: DocumentVisitor)Calls VisitDocumentStart, then calls Accept for all child nodes of the document and calls VisitDocumentEnd at the end.
AcceptStart(visitor: DocumentVisitor)Accepts a visitor for visiting the start of the document.
AcceptEnd(visitor: DocumentVisitor)Accepts a visitor for visiting the end of the document.
AppendDocument(srcDoc: Document, importFormatMode: ImportFormatMode)Appends the specified document to the end of this document.
AppendDocument(srcDoc: Document, importFormatMode: ImportFormatMode, importFormatOptions: ImportFormatOptions)Appends the specified document to the end of this document.
Save(fileName: string)Saves the document.
Save(fileName: string, saveFormat: SaveFormat)Saves the document to a file in the specified format.
Save(fileName: string, saveOptions: SaveOptions)Saves the document to a file using the specified save options.
Save(stream: Stream, saveFormat: SaveFormat)Overloads enable saving a document to a file name or a stream, optionally specifying a save format or detailed save options
Save(stream: Stream, saveOptions: SaveOptions)Calls Save(stream, saveOptions) on this Document instance.
Save(response: HttpResponse, fileName: string, contentDisposition: ContentDisposition, saveOptions: SaveOptions)Sends the document to the client browser.
EnsureMinimum()If the document contains no sections, creates one section with one paragraph.
AcceptAllRevisions()Accepts all tracked changes in the document.
Protect(type: ProtectionType)Protects the document from changes.
Protect(type: ProtectionType, password: string)Protects the document from changes and optionally sets a protection password.
Unprotect()Removes protection from the document.
Unprotect(password: string)Removes protection from the document if a correct password is specified.
UpdateTableLayout()Implements an earlier approach to table column widths re-calculation that has known issues.
UpdateListLabels()Updates list labels for all list items in the document.
UpdateActualReferenceMarks()Updates the ActualReferenceMark property of all footnotes and endnotes in the document.
RemoveMacros()Removes all macros (the VBA project) as well as toolbars and command customizations from the document.
UpdateFields()Updates the values of fields in the whole document.
UnlinkFields()Unlinks fields in the whole document.
NormalizeFieldTypes()Changes field type values FieldType of FieldStart, FieldSeparator, FieldEnd in the whole document so that they correspond to the field types contained in the field codes.
JoinRunsWithSameFormatting()Joins runs with same formatting in all paragraphs of the document.
ExpandTableStylesToDirectFormatting()Converts formatting specified in table styles into direct formatting on tables in the document.
Cleanup()Cleans unused styles and lists from the document.
Cleanup(options: CleanupOptions)Cleans unused styles and lists from the document depending on given CleanupOptions.
RemoveExternalSchemaReferences()Removes external XML schema references from this document.
StartTrackRevisions(author: string, dateTime: DateTime)Starts automatically marking all further changes you make to the document programmatically as revision changes.
StartTrackRevisions(author: string)Starts automatically marking all further changes you make to the document programmatically as revision changes.
StopTrackRevisions()Stops automatic marking of document changes as revisions.
CopyStylesFromTemplate(template: string)Copies styles from the specified template to a document.
CopyStylesFromTemplate(template: Document)Copies styles from the specified template to a document.
ImportNode(srcNode: Node, isImportChildren: bool)Imports a node from another document to the current document.
GetText()Gets the text of this node and of all its children.
GetChildNodes(nodeType: NodeType, isDeep: bool)Returns a collection of child nodes that match the specified type.
GetChild(nodeType: NodeType, index: int, isDeep: bool)Returns an Nth child node that matches the specified type.
SelectNodes(xpath: string)Selects a list of nodes matching the XPath expression.
SelectSingleNode(xpath: string)Selects the first Node that matches the XPath expression.
GetEnumerator()Provides support for the for each style iteration over the child nodes of this node.
AppendChild(newChild: T)Adds the specified node to the end of the list of child nodes for this node.
PrependChild(newChild: T)Adds the specified node to the beginning of the list of child nodes for this node.
InsertAfter(newChild: T, refChild: Node)Inserts the specified node immediately after the specified reference node.
InsertBefore(newChild: T, refChild: Node)Inserts the specified node immediately before the specified reference node.
RemoveChild(oldChild: T)Removes the specified child node.
RemoveAllChildren()Removes all the child nodes of the current node.
RemoveSmartTags()Removes all SmartTag descendant nodes of the current node.
IndexOf(child: Node)Returns the index of the specified child node in the child node array.
CreateNavigator()Creates navigator which can be used to traverse and read nodes.
GetAncestor(ancestorType: Type)Gets the first ancestor of the specified object type.
GetAncestorOf()Calls GetAncestorOf on this Document instance.
Remove()Removes itself from the parent.
NextPreOrder(rootNode: Node)Gets next node according to the pre-order tree traversal algorithm.
PreviousPreOrder(rootNode: Node)Gets the previous node according to the pre-order tree traversal algorithm.
ToString(saveFormat: SaveFormat)Exports the content of the node into a string in the specified format.
NodeTypeToString(nodeType: NodeType)A utility method that converts a node type enum value into a user friendly string.

See Also