Table of Contents

Class DocxFormValue

Namespace
DocToolkit
Assembly
DocToolkit.Docx.dll

A value read from, or written into, a Word content control.

public sealed class DocxFormValue
Inheritance
DocxFormValue
Inherited Members

Remarks

This type exists to make one guarantee structural. The library beneath offers WordContentControlPictureValue.FromFile(path), which reads the filesystem. This package deliberately refuses to read local files for images — see AllowLocalImages, which is false by default — so that route must not be reachable here either. There is therefore no picture factory taking a path or a URI. A caller who wants a file on disk reads it themselves, in one line, and the decision is visibly theirs.

Upstream models these values as object. A typed value is what turns that rule from something a guard has to remember into something this API cannot express.

Properties

Bytes

The image content, for Picture.

public byte[]? Bytes { get; }

Property Value

byte[]

Remarks

A copy, on the way in and on the way out. Without both, this sealed type with getter-only properties would not actually be immutable: a caller who kept their array could change what a value means after Validate had approved it and before Fill wrote it, and a caller could mutate what a report reports by writing through this property.

Checked

Whether the box is ticked, for Checked.

public bool? Checked { get; }

Property Value

bool?

Date

The date, for Date.

public DateTime? Date { get; }

Property Value

DateTime?

FileName

The image's file name, for Picture.

public string? FileName { get; }

Property Value

string

Kind

Which kind of value this is; which other properties are set follows from it.

public DocxFormValueKind Kind { get; }

Property Value

DocxFormValueKind

Text

The text — for Text, Choice and Other. Null otherwise.

public string? Text { get; }

Property Value

string

Methods

FromChecked(bool)

A check-box value.

public static DocxFormValue FromChecked(bool value)

Parameters

value bool

Whether the box is ticked.

Returns

DocxFormValue

FromChoice(string)

A drop-down or combo-box selection.

public static DocxFormValue FromChoice(string value)

Parameters

value string

The option to select.

Returns

DocxFormValue

Exceptions

ArgumentNullException

value is null.

FromDate(DateTime)

A date value.

public static DocxFormValue FromDate(DateTime value)

Parameters

value DateTime

The date to write.

Returns

DocxFormValue

FromPicture(byte[], string)

An image, from bytes. There is deliberately no overload taking a path — see the remarks on DocxFormValue.

public static DocxFormValue FromPicture(byte[] bytes, string fileName)

Parameters

bytes byte[]

The image content.

fileName string

A name for the image part, such as logo.png.

Returns

DocxFormValue

Exceptions

ArgumentNullException

bytes or fileName is null.

ArgumentException

bytes is empty, or fileName is blank.

FromText(string)

A plain-text value.

public static DocxFormValue FromText(string value)

Parameters

value string

The text to write.

Returns

DocxFormValue

Exceptions

ArgumentNullException

value is null.