# OfficeDoc Component

The OfficeDoc component implements support for the Open XML Packaging Format used in Office 2007 documents.

## Syntax

```text
nsoftware.IPWorksZip.OfficeDoc
```

## Remarks

The component provides a way to extract information and content from an Open XML packaged document, examine the package properties and basic read/update facilities.

## Property List

*The following is the full list of the properties of the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [ContentTypes](#contenttypes-property-officedoc-component) | Collection of content type entries |
| [Namespaces](#namespaces-property-officedoc-component) | Collection of namespaces in the current namespace stack. |
| [PackagePath](#packagepath-property-officedoc-component) | The path to the Open XML package file |
| [PackageProperties](#packageproperties-property-officedoc-component) | Collection of core/app/custom metadata properties associated with the archive. |
| [PartData](#partdata-property-officedoc-component) | The contents of the currently selected part. |
| [PartName](#partname-property-officedoc-component) | The name of the currently selected part |
| [Relationships](#relationships-property-officedoc-component) | Collection of Relationships in the current relationships (*.rels) file |
| [Validate](#validate-property-officedoc-component) | This property controls whether documents are validated during parsing. |
| [XAttributes](#xattributes-property-officedoc-component) | A collection of attributes of the current element. |
| [XChildren](#xchildren-property-officedoc-component) | Collection of child elements of the current element. |
| [XElement](#xelement-property-officedoc-component) | The name of the current element. |
| [XNamespace](#xnamespace-property-officedoc-component) | The namespace of the current element. |
| [XParent](#xparent-property-officedoc-component) | This property includes the parent of the current element. |
| [XPath](#xpath-property-officedoc-component) | This property provides a way to point to a specific element in the document. |
| [XPrefix](#xprefix-property-officedoc-component) | The prefix of the current element. |
| [XSubTree](#xsubtree-property-officedoc-component) | This property includes a snapshot of the current element in the document. |
| [XText](#xtext-property-officedoc-component) | The text of the current element. |

## Method List

*The following is the full list of the methods of the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [Close](#close-method-officedoc-component) | Closes the Open XML package archive |
| [Config](#config-method-officedoc-component) | Sets or retrieves a configuration setting. |
| [ExtractPart](#extractpart-method-officedoc-component) | Reads the contents of the currently selected part. |
| [FindPartByType](#findpartbytype-method-officedoc-component) | Looks up a part in the current relationships file by it's type namespace URI |
| [GetPropertyValue](#getpropertyvalue-method-officedoc-component) | Returns the value of the specified package property. |
| [ListParts](#listparts-method-officedoc-component) | List all the parts contained in the document and their relationships. |
| [Open](#open-method-officedoc-component) | Opens the Open XML package archive |
| [ParsePart](#parsepart-method-officedoc-component) | Parses the specified part as XML. |
| [ReadRelationships](#readrelationships-method-officedoc-component) | Reads the relationships file in the archive associated with the specified part |
| [ReplacePart](#replacepart-method-officedoc-component) | Replaces the contents of the specified part in the package. |
| [Reset](#reset-method-officedoc-component) | Resets the component. |
| [ResolveContentType](#resolvecontenttype-method-officedoc-component) | Returns the content type of the specified part. |

## Event List

*The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [BeginFile](#beginfile-event-officedoc-component) | Fired before each file is processed. |
| [Characters](#characters-event-officedoc-component) | This event is fired for plaintext segments of the input stream. |
| [Comment](#comment-event-officedoc-component) | This event is fired when a comment section is encountered. |
| [EndElement](#endelement-event-officedoc-component) | This event is fired when an end-element tag is encountered. |
| [EndFile](#endfile-event-officedoc-component) | Fired after each file is processed. |
| [EndPrefixMapping](#endprefixmapping-event-officedoc-component) | This event is fired when leaving the scope of a namespace declaration. |
| [Error](#error-event-officedoc-component) | Fired when information is available about errors during data delivery. |
| [EvalEntity](#evalentity-event-officedoc-component) | This event is fired every time an entity needs to be evaluated. |
| [IgnorableWhitespace](#ignorablewhitespace-event-officedoc-component) | This event is fired when a section of ignorable whitespace is encountered. |
| [Meta](#meta-event-officedoc-component) | This event fires when a meta section is encountered. |
| [Overwrite](#overwrite-event-officedoc-component) | Fired whenever a file exists and may be overwritten. |
| [PI](#pi-event-officedoc-component) | This event is fired when a processing instruction section is encountered. |
| [Progress](#progress-event-officedoc-component) | Fired as progress is made. |
| [SpecialSection](#specialsection-event-officedoc-component) | This event is fired when a special section is encountered. |
| [StartElement](#startelement-event-officedoc-component) | This event is fired when a begin-element tag is encountered in the document. |
| [StartPrefixMapping](#startprefixmapping-event-officedoc-component) | This event is fired when entering the scope of a namespace declaration. |

## Config Settings

*The following is a list of config settings for the component with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [NormalizePartName](#NormalizePartName) | Whether to normalize Part Names. |
| [RelationshipIsExternal\[x\]](#RelationshipIsExternal[x]) | Whether the relationship part is internal or external. |
| [BuildInfo](#BuildInfo) | Information about the product's build. |
| [GUIAvailable](#GUIAvailable) | Whether or not a message loop is available for processing events. |
| [LicenseInfo](#LicenseInfo) | Information about the current license. |
| [MaskSensitiveData](#MaskSensitiveData) | Whether sensitive data is masked in log messages. |
| [UseInternalSecurityAPI](#UseInternalSecurityAPI) | Whether or not to use the system security libraries or an internal implementation. |

# ContentTypes Property ([OfficeDoc](#officedoc-component) Component)

Collection of content type entries

## Syntax

```text
public ContentTypeList ContentTypes { get; }
```

## Remarks

Contains the default content types, as well as overrides for parts in the archive.

This property is read-only.

 Please refer to the [ContentType](#contenttype-type) type for a complete list of fields.

# Namespaces Property ([OfficeDoc](#officedoc-component) Component)

Collection of namespaces in the current namespace stack.

## Syntax

```text
public XMLNamespaceList Namespaces { get; }
```

## Remarks

This property contains a collection of XML namespaces, which are standards for providing uniquely named elements and attributes in an XML instance.

This collection is indexed from *0* to *Count - 1*.

This property is read-only and not available at design time.

 Please refer to the [XMLNamespace](#xmlnamespace-type) type for a complete list of fields.

# PackagePath Property ([OfficeDoc](#officedoc-component) Component)

The path to the Open XML package file

## Syntax

```text
public string PackagePath { get; set; }
```

## Default Value

""

## Remarks

This property specifies the path and filename of the Open XML package to work on.

# PackageProperties Property ([OfficeDoc](#officedoc-component) Component)

Collection of core/app/custom metadata properties associated with the archive.

## Syntax

```text
public PackagePropertyList PackageProperties { get; }
```

## Remarks

When the package is first opened using [Open](#open-method-officedoc-component), the component looks for any metadata property files in the archive and will expose their contents through this collection.

This property is read-only.

 Please refer to the [PackageProperty](#packageproperty-type) type for a complete list of fields.

# PartData Property ([OfficeDoc](#officedoc-component) Component)

The contents of the currently selected part.

## Syntax

```text
public string PartData { get; set; }
public byte[] PartDataB { get; set; }
```

## Default Value

""

## Remarks

This property will hold the contents of the part selected by [PartName](#partname-property-officedoc-component) after calling the [ExtractPart](#extractpart-method-officedoc-component) method. It can also be set before calling [ReplacePart](#replacepart-method-officedoc-component).

# PartName Property ([OfficeDoc](#officedoc-component) Component)

The name of the currently selected part

## Syntax

```text
public string PartName { get; set; }
```

## Default Value

""

## Remarks

This property specifies the name of the currently selected part in the document. If null or empty, no part is currently selected.

# Relationships Property ([OfficeDoc](#officedoc-component) Component)

Collection of Relationships in the current relationships (*.rels) file

## Syntax

```text
public RelationshipList Relationships { get; }
```

## Remarks

When the package is first opened using [Open](#open-method-officedoc-component), the top-level relationships file (/rels/.rels) is parsed and this collection populated with its contents. The [ReadRelationships](#readrelationships-method-officedoc-component) method can be used to populate this collection with the contents of other, part-specific relationship files, as needed.

This property is read-only.

 Please refer to the [Relationship](#relationship-type) type for a complete list of fields.

# Validate Property ([OfficeDoc](#officedoc-component) Component)

This property controls whether documents are validated during parsing.

## Syntax

```text
public bool Validate { get; set; }
```

## Default Value

True

## Remarks

When *true* (default), the document will be validated during parsing. To disable validation set Validate to *false*. Disabling validation may be useful in cases in which data can still be parsed even if the document is not well formed.

# XAttributes Property ([OfficeDoc](#officedoc-component) Component)

A collection of attributes of the current element.

## Syntax

```text
public XMLAttributeList XAttributes { get; }
```

## Remarks

This collection consists of all attributes of the current XML element. The component parses each attribute into a collection of [XMLAttribute](#xmlattribute-type) types.

This collection is indexed from *0* to *Count - 1*.

This property is read-only and not available at design time.

 Please refer to the [XMLAttribute](#xmlattribute-type) type for a complete list of fields.

# XChildren Property ([OfficeDoc](#officedoc-component) Component)

Collection of child elements of the current element.

## Syntax

```text
public XMLElementList XChildren { get; }
```

## Remarks

The elements are provided in the collection in the same order they are found in the document.

This collection is indexed from *0* to *Count - 1*.

This property is read-only and not available at design time.

 Please refer to the [XMLElement](#xmlelement-type) type for a complete list of fields.

# XElement Property ([OfficeDoc](#officedoc-component) Component)

The name of the current element.

## Syntax

```text
public string XElement { get; }
```

## Default Value

""

## Remarks

The current element is specified via the [XPath](#xpath-property-officedoc-component) property.

This property is read-only.

# XNamespace Property ([OfficeDoc](#officedoc-component) Component)

The namespace of the current element.

## Syntax

```text
public string XNamespace { get; }
```

## Default Value

""

## Remarks

The current element is specified via the [XPath](#xpath-property-officedoc-component) property.

This property is read-only.

# XParent Property ([OfficeDoc](#officedoc-component) Component)

This property includes the parent of the current element.

## Syntax

```text
public string XParent { get; }
```

## Default Value

""

## Remarks

The current element is specified through the [XPath](#xpath-property-officedoc-component) property.

This property is read-only.

# XPath Property ([OfficeDoc](#officedoc-component) Component)

This property provides a way to point to a specific element in the document.

## Syntax

```text
public string XPath { get; set; }
```

## Default Value

""

## Remarks

XPath implements a subset of the XML XPath specification, allowing you to point to specific elements in the XML document.

The path is a series of one or more element accessors separated by */*. The path can be absolute (starting with */*) or relative to the current XPath location.

 The following are possible values for an element accessor:

|  |  |
| --- | --- |
| 'name' | A particular element name |
| name[i] | The i-th subelement of the current element with the given name |
| [i] | The i-th subelement of the current element |
| [last()] | The last subelement of the current element |
| [last()-i] | The subelement located at the last location minus i in the current element |
| name[@attrname="attrvalue"] | The subelement containing a particular value for a given attribute (supports single AND double quotes) |
| .. | The parent of the current element |

 When XPath is set to a valid path, [XElement](#xelement-property-officedoc-component) points to the name of the element, with [XParent](#xparent-property-officedoc-component), [XNamespace](#xnamespace-property-officedoc-component), [XPrefix](#xprefix-property-officedoc-component), [XChildren](#xchildren-property-officedoc-component) , and [XText](#xtext-property-officedoc-component) providing other properties of the element. The attributes of the current element are provided in the [XAttributes](#xattributes-property-officedoc-component) collection.

BuildDOM must be set to *true* before parsing the document for the XPath functionality to be available.

**Example. Setting XPath:**

|  |  |
| --- | --- |
| Document root | XML.XPath = "/" |
| Specific Element | XML.XPath = "/root/SubElement1/SubElement2/" |
| i-th Child | XML.XPath = "/root/SubElement1[i]" |

# XPrefix Property ([OfficeDoc](#officedoc-component) Component)

The prefix of the current element.

## Syntax

```text
public string XPrefix { get; }
```

## Default Value

""

## Remarks

The current element is specified via the [XPath](#xpath-property-officedoc-component) property.

This property is read-only.

# XSubTree Property ([OfficeDoc](#officedoc-component) Component)

This property includes a snapshot of the current element in the document.

## Syntax

```text
public string XSubTree { get; }
```

## Default Value

""

## Remarks

The current element is specified through the [XPath](#xpath-property-officedoc-component) property. For this property to work, you must set [CacheContent](#CacheContent) to *true*.

This property is read-only.

# XText Property ([OfficeDoc](#officedoc-component) Component)

The text of the current element.

## Syntax

```text
public string XText { get; }
```

## Default Value

""

## Remarks

The current element is specified via the [XPath](#xpath-property-officedoc-component) property.

This property is read-only.

# Close Method ([OfficeDoc](#officedoc-component) Component)

Closes the Open XML package archive

## Syntax

```text
public void Close();

Async Version
public async Task Close();
public async Task Close(CancellationToken cancellationToken);
```

## Remarks

When this method is called, the component will close the current archive and release all resources.

# Config Method ([OfficeDoc](#officedoc-component) Component)

Sets or retrieves a configuration setting.

## Syntax

```text
public string Config(string configurationString);

Async Version
public async Task<string> Config(string configurationString);
public async Task<string> Config(string configurationString, CancellationToken cancellationToken);
```

## Remarks

Config is a generic method available in every component. It is used to set and retrieve [configuration settings](#config-settings-officedoc-component) for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these *internal properties* is provided through the Config method.

To set a configuration setting named *PROPERTY*, you must call *Config("PROPERTY=VALUE")*, where *VALUE* is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a [configuration setting](#config-settings-officedoc-component), you must call *Config("PROPERTY")*. The value will be returned as a string.

# ExtractPart Method ([OfficeDoc](#officedoc-component) Component)

Reads the contents of the currently selected part.

## Syntax

```text
public void ExtractPart();

Async Version
public async Task ExtractPart();
public async Task ExtractPart(CancellationToken cancellationToken);
```

## Remarks

If the part specified by the [PartName](#partname-property-officedoc-component) property exists, the corresponding physical file will be extracted from the archive and will be available through the [PartData](#partdata-property-officedoc-component) property.

If the part doesn't exists, or it's stored in interleaved format, an error will be raised.

# FindPartByType Method ([OfficeDoc](#officedoc-component) Component)

Looks up a part in the current relationships file by it's type namespace URI

## Syntax

```text
public string FindPartByType(string typeURI);

Async Version
public async Task<string> FindPartByType(string typeURI);
public async Task<string> FindPartByType(string typeURI, CancellationToken cancellationToken);
```

## Remarks

If a matching part can be found, it's part name is returned. Otherwise, an empty string is returned.

# GetPropertyValue Method ([OfficeDoc](#officedoc-component) Component)

Returns the value of the specified package property.

## Syntax

```text
public string GetPropertyValue(string propName, string propNamespace);

Async Version
public async Task<string> GetPropertyValue(string propName, string propNamespace);
public async Task<string> GetPropertyValue(string propName, string propNamespace, CancellationToken cancellationToken);
```

## Remarks

Looks up a package property named *PropName* in namespace *PropNamespace* in the core and app properties tables and returns it's value, if found.

If the property doesn't exists, an empty string is returned.

For custom properties. use an empty string ("") as the value of the *PropNamespace* parameter.

# ListParts Method ([OfficeDoc](#officedoc-component) Component)

List all the parts contained in the document and their relationships.

## Syntax

```text
public void ListParts();

Async Version
public async Task ListParts();
public async Task ListParts(CancellationToken cancellationToken);
```

## Remarks

When this method is called, the component will read all the relationships in the document, recursively, and populate the [Relationships](#relationships-property-officedoc-component) collection.

# Open Method ([OfficeDoc](#officedoc-component) Component)

Opens the Open XML package archive

## Syntax

```text
public void Open();

Async Version
public async Task Open();
public async Task Open(CancellationToken cancellationToken);
```

## Remarks

When this method is called, the component will attempt to open the archive specified in [PackagePath](#packagepath-property-officedoc-component) and extract package properties, content types and parse the master relationships file in the archive.

# ParsePart Method ([OfficeDoc](#officedoc-component) Component)

Parses the specified part as XML.

## Syntax

```text
public void ParsePart();

Async Version
public async Task ParsePart();
public async Task ParsePart(CancellationToken cancellationToken);
```

## Remarks

If the part specified by [PartName](#partname-property-officedoc-component) exists, the corresponding physical file will be extracted from the archive and parsed as XML. If BuildDOM is enabled, the DOM will be built internally and you can use XPath to query the resulting document, using the [XPath](#xpath-property-officedoc-component) property. If BuildDOM is disabled, only the XML parser-related events will be fired.

# ReadRelationships Method ([OfficeDoc](#officedoc-component) Component)

Reads the relationships file in the archive associated with the specified part

## Syntax

```text
public void ReadRelationships();

Async Version
public async Task ReadRelationships();
public async Task ReadRelationships(CancellationToken cancellationToken);
```

## Remarks

When this method is called, the component will look for a .rels file associated with the part specified by the [PartName](#partname-property-officedoc-component) property. If found, the [Relationships](#relationships-property-officedoc-component) collection will now expose the contents of the relationships for that part.

# ReplacePart Method ([OfficeDoc](#officedoc-component) Component)

Replaces the contents of the specified part in the package.

## Syntax

```text
public void ReplacePart();

Async Version
public async Task ReplacePart();
public async Task ReplacePart(CancellationToken cancellationToken);
```

## Remarks

If the part specified by the [PartName](#partname-property-officedoc-component) property exists, the corresponding physical file will be replaced with the contents of the [PartData](#partdata-property-officedoc-component) property. The package file will be modified in place right away.

If the part doesn't exists, it's stored in interleaved format, or [PartData](#partdata-property-officedoc-component) is null or empty, an error will be raised.

# Reset Method ([OfficeDoc](#officedoc-component) Component)

Resets the component.

## Syntax

```text
public void Reset();

Async Version
public async Task Reset();
public async Task Reset(CancellationToken cancellationToken);
```

## Remarks

Reset resets the state of the component. All properties will be set to their default values, and any files open will be closed.

# ResolveContentType Method ([OfficeDoc](#officedoc-component) Component)

Returns the content type of the specified part.

## Syntax

```text
public string ResolveContentType();

Async Version
public async Task<string> ResolveContentType();
public async Task<string> ResolveContentType(CancellationToken cancellationToken);
```

## Remarks

Applies the content type resolution rules specified in the Open XML packaging specification and returns the content type associated with [PartName](#partname-property-officedoc-component) in the archive.

If there's no content type mapped for the part or for the extension, an empty string is returned.

# BeginFile Event ([OfficeDoc](#officedoc-component) Component)

Fired before each file is processed.

## Syntax

```text
public event OnBeginFileHandler OnBeginFile;

public delegate void OnBeginFileHandler(object sender, OfficeDocBeginFileEventArgs e);

public class OfficeDocBeginFileEventArgs : EventArgs {
  public int Index { get; }
  public bool Skip { get; set; }
}
```

## Remarks

BeginFile is fired before each file is processed by the compressor or decompressor, as appropriate. *Index* contains the array index of the file about to be processed, and the [CompressedName](#@@OfficeDoc_Files@@_f_CompressedName), [DecompressedName](#@@OfficeDoc_Files@@_f_DecompressedName), [CompressedSize](#@@OfficeDoc_Files@@_f_CompressedSize) (decompression only), and [DecompressedSize](#@@OfficeDoc_Files@@_f_DecompressedSize) fields of the Files collection for this index contain more detailed information about the file about to be processed.

When extracting, an alternate location may be specified by trapping the event, and modifying [DecompressedName](#@@OfficeDoc_Files@@_f_DecompressedName) and/or ExtractToPath. If [DecompressedName](#@@OfficeDoc_Files@@_f_DecompressedName) is set to an empty string, the file will not be written to disk. If [WriteToProgressEvent](#WriteToProgressEvent) is true, the file will still be decompressed, and the data may be extracted through the [Progress](#progress-event-officedoc-component) event.

This event may also be trapped while compressing. [CompressedName](#@@OfficeDoc_Files@@_f_CompressedName) and [DecompressedName](#@@OfficeDoc_Files@@_f_DecompressedName) may be changed.

 You may set the *Skip* parameter to true in order to skip the file completely while compressing or extracting.

# Characters Event ([OfficeDoc](#officedoc-component) Component)

This event is fired for plaintext segments of the input stream.

## Syntax

```text
public event OnCharactersHandler OnCharacters;

public delegate void OnCharactersHandler(object sender, OfficeDocCharactersEventArgs e);

public class OfficeDocCharactersEventArgs : EventArgs {
  public string Text { get; }
}
```

## Remarks

The Characters event provides the plaintext content of the XML document (i.e., the text inside the tags). The text is provided through the *Text* parameter.

The text includes whitespace as well as end-of-line characters, except for ignorable whitespace, which is fired through the [IgnorableWhitespace](#ignorablewhitespace-event-officedoc-component) event.

# Comment Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when a comment section is encountered.

## Syntax

```text
public event OnCommentHandler OnComment;

public delegate void OnCommentHandler(object sender, OfficeDocCommentEventArgs e);

public class OfficeDocCommentEventArgs : EventArgs {
  public string Text { get; }
}
```

## Remarks

The Comment event is fired whenever a comment section (*<!-- ...text... -->*) is found in the document.

The full text of the comment is provided by the *Text* parameter.

# EndElement Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when an end-element tag is encountered.

## Syntax

```text
public event OnEndElementHandler OnEndElement;

public delegate void OnEndElementHandler(object sender, OfficeDocEndElementEventArgs e);

public class OfficeDocEndElementEventArgs : EventArgs {
  public string Namespace { get; }
  public string Element { get; }
  public string QName { get; }
  public bool IsEmpty { get; }
}
```

## Remarks

The EndElement event is fired when an end-element tag is found in the document.

The element name is provided by the *Element* parameter.

The *IsEmpty* parameter is *true* when the event corresponds to an empty element declaration.

# EndFile Event ([OfficeDoc](#officedoc-component) Component)

Fired after each file is processed.

## Syntax

```text
public event OnEndFileHandler OnEndFile;

public delegate void OnEndFileHandler(object sender, OfficeDocEndFileEventArgs e);

public class OfficeDocEndFileEventArgs : EventArgs {
  public int Index { get; }
}
```

## Remarks

EndFile is fired after each file is processed by the compressor or decompressor, as appropriate. *Index* contains the array index of the file processed, and the [CompressedName](#@@OfficeDoc_Files@@_f_CompressedName), [DecompressedName](#@@OfficeDoc_Files@@_f_DecompressedName), [CompressedSize](#@@OfficeDoc_Files@@_f_CompressedSize), and [DecompressedSize](#@@OfficeDoc_Files@@_f_DecompressedSize) fields in the Files collection for this index contain more detailed information about the file processed.

# EndPrefixMapping Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when leaving the scope of a namespace declaration.

## Syntax

```text
public event OnEndPrefixMappingHandler OnEndPrefixMapping;

public delegate void OnEndPrefixMappingHandler(object sender, OfficeDocEndPrefixMappingEventArgs e);

public class OfficeDocEndPrefixMappingEventArgs : EventArgs {
  public string Prefix { get; }
}
```

## Remarks

The [StartPrefixMapping](#startprefixmapping-event-officedoc-component) event is fired when entering the scope of a namespace declaration.

# Error Event ([OfficeDoc](#officedoc-component) Component)

Fired when information is available about errors during data delivery.

## Syntax

```text
public event OnErrorHandler OnError;

public delegate void OnErrorHandler(object sender, OfficeDocErrorEventArgs e);

public class OfficeDocErrorEventArgs : EventArgs {
  public int ErrorCode { get; }
  public string Description { get; }
}
```

## Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the component throws an exception.

The *ErrorCode* parameter contains an error code, and the *Description* parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the [Error Codes](#trappable-errors-officedoc-component) section.

# EvalEntity Event ([OfficeDoc](#officedoc-component) Component)

This event is fired every time an entity needs to be evaluated.

## Syntax

```text
public event OnEvalEntityHandler OnEvalEntity;

public delegate void OnEvalEntityHandler(object sender, OfficeDocEvalEntityEventArgs e);

public class OfficeDocEvalEntityEventArgs : EventArgs {
  public string Entity { get; }
  public string Value { get; set; }
}
```

## Remarks

The *Value* parameter contains a suggested value for the entity (normally the entity name itself). You may set *Value* to a value of your choice, which will later be passed into the text stream.

# IgnorableWhitespace Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when a section of ignorable whitespace is encountered.

## Syntax

```text
public event OnIgnorableWhitespaceHandler OnIgnorableWhitespace;

public delegate void OnIgnorableWhitespaceHandler(object sender, OfficeDocIgnorableWhitespaceEventArgs e);

public class OfficeDocIgnorableWhitespaceEventArgs : EventArgs {
  public string Text { get; }
}
```

## Remarks

The ignorable whitespace section is provided by the *Text* parameter.

# Meta Event ([OfficeDoc](#officedoc-component) Component)

This event fires when a meta section is encountered.

## Syntax

```text
public event OnMetaHandler OnMeta;

public delegate void OnMetaHandler(object sender, OfficeDocMetaEventArgs e);

public class OfficeDocMetaEventArgs : EventArgs {
  public string Text { get; }
}
```

## Remarks

The Meta event is fired whenever a meta information section (*<! ...text... >*) is found in the document.

The full text of the meta section is provided by the *Text* parameter.

# Overwrite Event ([OfficeDoc](#officedoc-component) Component)

Fired whenever a file exists and may be overwritten.

## Syntax

```text
public event OnOverwriteHandler OnOverwrite;

public delegate void OnOverwriteHandler(object sender, OfficeDocOverwriteEventArgs e);

public class OfficeDocOverwriteEventArgs : EventArgs {
  public string FileName { get; set; }
  public bool Overwrite { get; set; }
}
```

## Remarks

Overwrite is fired when a file is about to be overwritten, and would overwrite an existing file. The event is fired during decompression.

*FileName* contains the full name of the file, specified with its pathname.

*Overwrite* specifies whether or not the file will be overwritten. For Zip, Jar, and Tar, this is equal by default to the value of the OverwriteFiles property. For Gzip, this value defaults to true.

Either of the parameters may be changed when the event is fired. Changing the value of *Overwrite* will override the default behavior of the component, and cause the file to be overwritten or not overwritten, depending on the value set. If *FileName* is changed, the value of *Overwrite* will be ignored, and the file will be written with the specified name. If a file of the new name also exists this file will be silently overwritten.

# PI Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when a processing instruction section is encountered.

## Syntax

```text
public event OnPIHandler OnPI;

public delegate void OnPIHandler(object sender, OfficeDocPIEventArgs e);

public class OfficeDocPIEventArgs : EventArgs {
  public string Text { get; }
}
```

## Remarks

The PI event is fired whenever a processing instruction section (*<? ...text... ?>*) is found in the document.

The full text of the processing instruction is provided by the *Text* parameter.

# Progress Event ([OfficeDoc](#officedoc-component) Component)

Fired as progress is made.

## Syntax

```text
public event OnProgressHandler OnProgress;

public delegate void OnProgressHandler(object sender, OfficeDocProgressEventArgs e);

public class OfficeDocProgressEventArgs : EventArgs {
  public string Data { get; }  public byte[] DataB { get; }
  public string FileName { get; }
  public long BytesProcessed { get; }
  public int PercentProcessed { get; }
}
```

## Remarks

The Progress event is automatically fired as compression or decompression is performed. When [WriteToProgressEvent](#WriteToProgressEvent) is true, the output data is provided through the *Data* parameter, allowing for it to be streamed out.

*FileName* contains the name of the file being written. If no file is being written, *FileName* will contain an empty string, and the output data will be provided exclusively through this event.

*BytesProcessed* contains the total number of uncompressed bytes processed. *PercentProcessed* contains the percent of uncompressed bytes processed, corresponding roughly to the running time of the operation.

For **Gzip** extraction only, *BytesProcessed* and *PercentProcessed* will reflect the number of compressed bytes extracted, as it is generally impossible to predetermine the total uncompressed size.

If [WriteToProgressEvent](#WriteToProgressEvent) is false, *Data* will contain null.

# SpecialSection Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when a special section is encountered.

## Syntax

```text
public event OnSpecialSectionHandler OnSpecialSection;

public delegate void OnSpecialSectionHandler(object sender, OfficeDocSpecialSectionEventArgs e);

public class OfficeDocSpecialSectionEventArgs : EventArgs {
  public string SectionId { get; }
  public string Text { get; }
}
```

## Remarks

The SpecialSection event is fired whenever a special section (such as *<![ CDATA [ ...text... ]]>*) is found in the document.

The full text of the special section is provided by the *Text* parameter, and the *SectionId* parameter provides the section identifier (e.g., *CDATA*).

# StartElement Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when a begin-element tag is encountered in the document.

## Syntax

```text
public event OnStartElementHandler OnStartElement;

public delegate void OnStartElementHandler(object sender, OfficeDocStartElementEventArgs e);

public class OfficeDocStartElementEventArgs : EventArgs {
  public string Namespace { get; }
  public string Element { get; }
  public string QName { get; }
  public bool IsEmpty { get; }
}
```

## Remarks

The StartElement event is fired when a begin-element tag is found in the document.

The element name is provided through the *Element* parameter. The attribute names and values (if any) are provided through the [XAttributes](#xattributes-property-officedoc-component) collection.

The *IsEmpty* parameter is *true* when the event corresponds to an empty element declaration.

# StartPrefixMapping Event ([OfficeDoc](#officedoc-component) Component)

This event is fired when entering the scope of a namespace declaration.

## Syntax

```text
public event OnStartPrefixMappingHandler OnStartPrefixMapping;

public delegate void OnStartPrefixMappingHandler(object sender, OfficeDocStartPrefixMappingEventArgs e);

public class OfficeDocStartPrefixMappingEventArgs : EventArgs {
  public string Prefix { get; }
  public string URI { get; }
}
```

## Remarks

The [EndPrefixMapping](#endprefixmapping-event-officedoc-component) event is fired when leaving the scope of a namespace declaration.

# ContentType Type

The Content Type entry as defined in the package

## Remarks

The content type represents an entry in the [Content_Types].xml file in the archive. It can either represent a default type associated with an extension, or an override specific to a given part in the archive.

The following fields are available:

- [IsOverride](#ContentType_f_IsOverride)

- [MediaType](#ContentType_f_MediaType)

- [Target](#ContentType_f_Target)

## Fields

 **IsOverride** *bool (read-only)*
Default: True

Specifies if this is a default content type or an override.

 **MediaType** *string (read-only)*
Default: ""

The media type for this entry, as defined by RFC2616.

 **Target** *string (read-only)*
Default: ""

If it's a default content type, this will be the file extension it applies to. Otherwise, it will be the part name.

## Constructors

```text
public ContentType();
```

# PackageProperty Type

A core/app/custom metadata property attached to the package

## Remarks

A property is an entry in one of the package's property files.

All the properties, including core Open XML properties, application-specific properties and custom properties are represented here using the same structure.

The following fields are available:

- [DataType](#PackageProperty_f_DataType)

- [Name](#PackageProperty_f_Name)

- [Namespace](#PackageProperty_f_Namespace)

- [PropId](#PackageProperty_f_PropId)

- [PropSet](#PackageProperty_f_PropSet)

- [Value](#PackageProperty_f_Value)

## Fields

 **DataType** *string (read-only)*
Default: ""

The data type associated with this property, if the information is available.

 **Name** *string (read-only)*
Default: ""

The name of this property

 **Namespace** *string (read-only)*
Default: ""

The XML Namespace URI associated with this property. For custom properties, this will be an empty string.

 **PropId** *string (read-only)*
Default: ""

If this is a custom property, this will be the pid assigned to it.

 **PropSet** *string (read-only)*
Default: ""

If this is a custom property, this will be the GUID of the property set it belongs to.

 **Value** *string (read-only)*
Default: ""

The value of this property

## Constructors

```text
public PackageProperty();
```

# Relationship Type

A relationship entry in a .rels file in the archive

## Remarks

A relationship represents a reference to another part within the archive.

A relationship entry specifies a part name, the type of relationship (what it means) and a unique Id for this relation in the currently selected relationship file.

The following fields are available:

- [ContentType](#Relationship_f_ContentType)

- [Id](#Relationship_f_Id)

- [PartName](#Relationship_f_PartName)

- [TypeURI](#Relationship_f_TypeURI)

## Fields

 **ContentType** *string (read-only)*
Default: ""

The content type for the part referenced by this relationship, resolved from [Content_Types].xml according to the Open XML packaging specification rules.

 **Id** *string (read-only)*
Default: ""

The unique ID of this relationship within this .rels file

 **PartName** *string (read-only)*
Default: ""

The name of the part this relationship entry applies to.

 **TypeURI** *string (read-only)*
Default: ""

The XML namespace URI that specifies the meaning of this relationship.

## Constructors

```text
public Relationship();
```

# XMLAttribute Type

This type describes an XML attribute from the current XML element.

## Remarks

This type describes an XML attribute from the current element. It includes fields to denote information about the attribute being defined.

The following fields are available:

- [Name](#XMLAttribute_f_Name)

- [Namespace](#XMLAttribute_f_Namespace)

- [Prefix](#XMLAttribute_f_Prefix)

- [Value](#XMLAttribute_f_Value)

## Fields

 **Name** *string (read-only)*
Default: ""

The [Name](#XMLAttribute_f_Name) provides the local name (without prefix) of the attribute.

 **Namespace** *string (read-only)*
Default: ""

This field contains the attribute namespace.

 **Prefix** *string (read-only)*
Default: ""

This field contains the attribute prefix (if any). If the attribute does not have a prefix, this field is empty.

 **Value** *string (read-only)*
Default: ""

This field contains the attribute value.

## Constructors

```text
public XMLAttribute();
```

# XMLElement Type

This type describes an element contained within the XML document.

## Remarks

This type describes an XML element. The fields for this type describe the element [Name](#XMLElement_f_Name), [Prefix](#XMLElement_f_Prefix), and [Namespace](#XMLElement_f_Namespace) of the given element.

The elements are inserted into the array in the same order they are found in the document.

The following fields are available:

- [Name](#XMLElement_f_Name)

- [Namespace](#XMLElement_f_Namespace)

- [Prefix](#XMLElement_f_Prefix)

- [XText](#XMLElement_f_XText)

## Fields

 **Name** *string (read-only)*
Default: ""

The [Name](#XMLElement_f_Name) field provides the local name (without a prefix) of the element.

 **Namespace** *string (read-only)*
Default: ""

This field contains the namespace of the element.

 **Prefix** *string (read-only)*
Default: ""

This field contains the prefix of the element (if any). If the element does not have a prefix, this field is empty.

 **XText** *string (read-only)*
Default: ""

This field contains the inner text of the element.

## Constructors

```text
public XMLElement();
```

# XMLNamespace Type

This type describes an XML namespace from the current namespace stack.

## Remarks

This type describes an XML namespace from the current stack. It includes fields to denote the [Prefix](#XMLNamespace_f_Prefix) and the [URI](#XMLNamespace_f_URI) of the namespace being defined.

The default namespace exists at index *0*. The [Prefix](#XMLNamespace_f_Prefix) field at index *0* is *xmlns*, and the [Name](#XMLNamespace_f_Name) field contains the default namespace.

The following fields are available:

- [Prefix](#XMLNamespace_f_Prefix)

- [URI](#XMLNamespace_f_URI)

## Fields

 **Prefix** *string*
Default: ""

This field contains the [Prefix](#XMLNamespace_f_Prefix) for the namespace.

 **URI** *string*
Default: ""

This field contains the namespace URI associated with the corresponding [Prefix](#XMLNamespace_f_Prefix). This URL is usually pointing to the XML schema for the namespace.

## Constructors

```text
public XMLNamespace();
```

```text
public XMLNamespace(string URI, string prefix);
```

# Config Settings ([OfficeDoc](#officedoc-component) Component)

 The component accepts one or more of the following *configuration settings*. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these *internal properties* is provided through the [Config](#config-method-officedoc-component) method.

### OfficeDoc Config Settings

**NormalizePartName**: Whether to normalize Part Names.Sometimes the Part Names retrieved from a document will be of a format that is not directly usable in the [PartName](#partname-property-officedoc-component) property when retrieving the part. For example:

```text
/ppt/slides/../media/image1.jpeg
```

When this option is set to True the component will automatically normalize these Part Names so that they can be directly used in the [PartName](#partname-property-officedoc-component) property for retrieving the part. For example, the above would become:

```text
/ppt/media/image1.jpeg
```

The default is True.

**RelationshipIsExternal[x]**: Whether the relationship part is internal or external.Some relationships in an Office document may be external items, such as URLs and files on disk. These relationships are not directly accessible via [ExtractPart](#extractpart-method-officedoc-component). This configuration option will return "True" if the relationship at index "x" of [Relationships](#relationships-property-officedoc-component) is an external part. Otherwise it will return "False"

### Base Config Settings

**BuildInfo**: Information about the product's build.When queried, this setting will return a string containing information about the product's build.

**GUIAvailable**: Whether or not a message loop is available for processing events.In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The component will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting [GUIAvailable](#GUIAvailable) to *false* will ensure that the component does not attempt to process external events.

**LicenseInfo**: Information about the current license.When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
- Last Valid Build: The last valid build number for which the license will work.

**MaskSensitiveData**: Whether sensitive data is masked in log messages.In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to *true* to mask sensitive data. The default is *true*.

**UseInternalSecurityAPI**: Whether or not to use the system security libraries or an internal implementation. When set to *false*, the component will use the system security libraries by default to perform cryptographic functions where applicable. In this case, calls to unmanaged code will be made. In certain environments, this is not desirable. To use a completely managed security implementation, set this setting to *true*.

Setting this configuration setting to *true* tells the component to use the internal implementation instead of using the system security libraries.

 On Windows, this setting is set to *false* by default. On Linux/macOS, this setting is set to *true* by default.

NOTE: This setting is static. The value set is applicable to all components used in the application.

When this value is set, the product's system dynamic link library (DLL) is no longer required as a reference, as all unmanaged code is stored in that file.

# Trappable Errors ([OfficeDoc](#officedoc-component) Component)

 **Errors**

The following errors may be generated by the component. Note that frequently the error message will contain more specific information than what is listed here.

Note that some non-fatal errors may be trapped and explicitly ignored in the [Error](#error-event-officedoc-component) event. This will allow the component to continue operation even in case of error.

### OfficeDoc Errors

|  |  |
| --- | --- |
| 268 | The specified part name could not be found on the package, or the part is stored in interleaved format. |
