DataObject.GetData Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Returns the data associated with the specified data format.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public virtual object GetData(
	string format


Type: System.String

The format of the data to retrieve. See DataFormats for predefined formats.

Return Value

Type: System.Object

The data associated with the specified format, or null.

If this method cannot find data in the specified format, it attempts to convert the data to the format. If the data cannot be converted to the specified format, or if the data was stored with automatic conversion set to false, this method returns null.

To determine whether data is associated with, or can be converted to, a format, call GetDataPresent before calling GetData. Call GetFormats for a list of valid formats for the data stored in this DataObject.


Data can be converted to another format if it was stored specifying that conversion is allowed, and if the requested format is compatible with the stored format. For example, data stored as Unicode can be converted to text.

When format is Html, this method returns a UTF-8 encoded string in applications that target .NET 4.5 or higher, and an ANSI encoded string in applications that target .NET 4.0 or lower.

The following code example retrieves the data stored in a DataObject. First, a new DataObject is created with text data. Then, the data is retrieved, specifying its format as a string, and displayed in a text box.

This code requires that textBox1 has been created.

private void AddMyData3() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();

    // Creates a new data object.
    DataObject myDataObject = new DataObject();

    // Adds the component to the DataObject.

    // Prints whether data of the specified type is in the DataObject.
    Type myType = myComponent.GetType();
       textBox1.Text = "Data of type " + myType.ToString() + 
       " is present in the DataObject";
       textBox1.Text = "Data of type " + myType.ToString() +
       " is not present in the DataObject";

.NET Framework
Available since 1.1
Return to top