HtmlTextWriter.Write Method

Definition

Writes the specified data type to the output stream, along with any pending tab spacing.

Overloads

Write(Boolean)

Writes the text representation of a Boolean value to the output stream, along with any pending tab spacing.

Write(Char)

Writes the text representation of a Unicode character to the output stream, along with any pending tab spacing.

Write(Char[])

Writes the text representation of an array of Unicode characters to the output stream, along with any pending tab spacing.

Write(Double)

Writes the text representation of a double-precision floating-point number to the output stream, along with any pending tab spacing.

Write(Int32)

Writes the text representation of a 32-byte signed integer to the output stream, along with any pending tab spacing.

Write(Int64)

Writes the text representation of a 64-byte signed integer to the output stream, along with any pending tab spacing.

Write(Object)

Writes the text representation of an object to the output stream, along with any pending tab spacing.

Write(Single)

Writes the text representation of a single-precision floating-point number to the output stream, along with any pending tab spacing.

Write(String)

Writes the specified string to the output stream, along with any pending tab spacing.

Write(String, Object)

Writes a tab string and a formatted string to the output stream, using the same semantics as the Format(String, Object) method, along with any pending tab spacing.

Write(String, Object[])

Writes a formatted string that contains the text representation of an object array to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object[]) method.

Write(Char[], Int32, Int32)

Writes the text representation of a subarray of Unicode characters to the output stream, along with any pending tab spacing.

Write(String, Object, Object)

Writes a formatted string that contains the text representation of two objects to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object, Object) method.

Write(Boolean)

Writes the text representation of a Boolean value to the output stream, along with any pending tab spacing.

public override void Write (bool value);

Parameters

value
Boolean

The Boolean to write to the output stream.

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Char)

Writes the text representation of a Unicode character to the output stream, along with any pending tab spacing.

public override void Write (char value);

Parameters

value
Char

The Unicode character to write to the output stream.

Examples

The following code example demonstrates using the Write method to end the opening tag of an <img> element by using the TagRightChar constant.

This code example renders the following markup:

<img alt="A custom image">

</img>

// Create a manually rendered <img> element
// that contains an alt attribute.
writer.WriteBeginTag("img");
writer.WriteAttribute("alt", "A custom image.");
writer.Write(HtmlTextWriter.TagRightChar);
writer.WriteEndTag("img");

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Char[])

Writes the text representation of an array of Unicode characters to the output stream, along with any pending tab spacing.

public override void Write (char[] buffer);

Parameters

buffer
Char[]

The array of Unicode characters to write to the output stream.

Examples

This section provides two code examples. The first one demonstrates how to create an array of characters. The second one demonstrates how to use the array.

These code examples generate the following markup:

<label>

hello world

</label>

The following code example demonstrates how to create an array of characters that spell out hello world. Included in the array is the SpaceChar field, which creates a space between the two words.

private char[] testChars = {'h', 'e', 'l', 'l', 'o',
    HtmlTextWriter.SpaceChar ,'w', 'o', 'r', 'l', 'd'};

The following code example demonstrates how to use the Write method to render the hello world character array created in the preceding code example to a page, when the control that contains this example code is included in a page.

// Render a character array as the 
// contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(testChars);
writer.RenderEndTag();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Double)

Writes the text representation of a double-precision floating-point number to the output stream, along with any pending tab spacing.

public override void Write (double value);

Parameters

value
Double

The double-precision floating-point number to write to the output stream.

Examples

The following code example shows how to use the Write method to render the value of the Double.MaxValue field.

This code example generates the following markup:

<label>

1.79769313486232E+308

</label>

// Use the Write(Double) method to render
// the MaxValue field of the Double structure. 
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(Double.MaxValue);
writer.RenderEndTag();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Int32)

Writes the text representation of a 32-byte signed integer to the output stream, along with any pending tab spacing.

public override void Write (int value);

Parameters

value
Int32

The 32-byte signed integer to write to the output stream.

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Int64)

Writes the text representation of a 64-byte signed integer to the output stream, along with any pending tab spacing.

public override void Write (long value);

Parameters

value
Int64

The 64-byte signed integer to write to the output stream.

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Object)

Writes the text representation of an object to the output stream, along with any pending tab spacing.

public override void Write (object value);

Parameters

value
Object

The object to write to the output stream.

Examples

The following code example shows how to use the Write method to render the value of the CultureInfo.CurrentCulture property.

This code example generates the following markup:

This is a rendered CultureInfo object.

<bold>

The value of the CurrentCulture property:

</bold>

// Use the Write method to render an arbitrary
// object, in this case a CultureInfo object. 
writer.Write("This is a rendered CultureInfo Object.");
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write(CultureInfo.CurrentCulture);
writer.RenderEndTag();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Single)

Writes the text representation of a single-precision floating-point number to the output stream, along with any pending tab spacing.

public override void Write (float value);

Parameters

value
Single

The single-precision floating-point number to write to the output stream.

Examples

The following code example demonstrates how to use the Write method to render the value of the Single.Epsilon field, which is the smallest possible value of the Single structure.

This code example generates the following markup:

<b>

1.401298E-45

</b>

// Use the Write(Single) method to render the
// Epsilon field of the Single structure. 
writer.RenderBeginTag(HtmlTextWriterTag.B);
writer.Write(Single.Epsilon);
writer.RenderEndTag();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(String)

Writes the specified string to the output stream, along with any pending tab spacing.

public override void Write (string s);

Parameters

s
String

The string to write to the output stream.

Examples

The following code example demonstrates how to use the Write method to render a string between the opening and closing tags of a custom markup element.

This code example generates the following markup:

<MyTag>

Contents of MyTag

</MyTag>

// Create a non-standard tag.
writer.RenderBeginTag("MyTag");
writer.Write("Contents of MyTag");
writer.RenderEndTag();
writer.WriteLine();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(String, Object)

Writes a tab string and a formatted string to the output stream, using the same semantics as the Format(String, Object) method, along with any pending tab spacing.

public override void Write (string format, object arg0);

Parameters

format
String

A string that contains zero or more format items.

arg0
Object

An object to format.

Examples

The following code example shows how to use the Write method to render a formatted string with the value of the CurrentCulture property.

// Use the Write(string, object) method to
// render a formatted string and an object in it.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The current cultural settings are {0}",
    CultureInfo.CurrentCulture);
writer.RenderEndTag();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(String, Object[])

Writes a formatted string that contains the text representation of an object array to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object[]) method.

public override void Write (string format, params object[] arg);

Parameters

format
String

A string that contains zero or more format items.

arg
Object[]

An object array to format.

Examples

This section contains two code examples. The first one demonstrates how to render a formatted string and the contents of an array. The second one demonstrates how to declare the array.

The following code example shows how to use the Write method to render a formatted string and the contents of an object array, named curPriceTime. The method call renders the second member of the array before it renders the first member.

// Render a formatted string and the
// text representation of an object array,
// myObjectArray, as the contents of
// a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The trade value at {1} is ${0}.", curPriceTime);
writer.RenderEndTag();

The following code example demonstrates declaring the curPriceTime object array.

private object[] curPriceTime = {4.25, DateTime.Now};

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(Char[], Int32, Int32)

Writes the text representation of a subarray of Unicode characters to the output stream, along with any pending tab spacing.

public override void Write (char[] buffer, int index, int count);

Parameters

buffer
Char[]

The array of characters from which to write text to the output stream.

index
Int32

The index location in the array where writing begins.

count
Int32

The number of characters to write to the output stream.

Examples

This section provides two code examples. The first one demonstrates how to create a character array. The second one demonstrates how to use the array.

These code examples generate the following markup:

<label>

hello

</label>

The following code example shows how to create an array of characters that spell out hello world. Included in the array is the SpaceChar field, which creates a space between the two words.

private char[] testChars = {'h', 'e', 'l', 'l', 'o',
    HtmlTextWriter.SpaceChar ,'w', 'o', 'r', 'l', 'd'};

The following portion of the code example uses the index and count parameters of the Write method to render the first five characters of the array created in the preceding example.

// Render a subarray of a character array
// as the contents of a <label> element.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write(testChars, 0, 5);
writer.RenderEndTag();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Write(String, Object, Object)

Writes a formatted string that contains the text representation of two objects to the output stream, along with any pending tab spacing. This method uses the same semantics as the Format(String, Object, Object) method.

public override void Write (string format, object arg0, object arg1);

Parameters

format
String

A string that contains zero or more format items.

arg0
Object

An object to format.

arg1
Object

An object to format.

Examples

The following code example shows how to use the Write method to render a formatted string and the values of the CurrentCulture and Today properties.

// Use the Write(string,object,object) method to
// render a formatted string and two objects 
// in the string.
writer.RenderBeginTag(HtmlTextWriterTag.Label);
writer.Write("The current cultural settings are {0}. Today's date is {1}.",
    CultureInfo.CurrentCulture, DateTime.Today);
writer.RenderEndTag();

Remarks

The Write method generates any tabs that are pending, and then calls the Write base method.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1