DataObject.GetFormats Method

Definition

Returns a list of formats in which the data in this data object is stored, or can be converted to.

Overloads

GetFormats()

Returns a list of formats in which the data in this data object is stored, or can be converted to.

GetFormats(Boolean)

Returns a list of formats in which the data in this data object is stored. A Boolean flag indicates whether to also include formats that the data can be automatically converted to.

GetFormats()

Returns a list of formats in which the data in this data object is stored, or can be converted to.

C#
public string[] GetFormats();

Returns

String[]

An array of strings, with each string specifying the name of a format that this data object supports.

Implements

Examples

The following example uses this method to get an array of strings denoting all data formats available in a data object (both native and auto-convertible).

C#
DataObject dataObject = new DataObject("Some string data to store...");

// Get an array of strings, each string denoting a data format
// that is available in the data object.  This overload of GetDataFormats
// returns all available data formats, native and auto-convertible.
string[] dataFormats = dataObject.GetFormats();

// Get the number of data formats present in the data object, including both
// auto-convertible and native data formats.
int numberOfDataFormats = dataFormats.Length;

// To enumerate the resulting array of data formats, and take some action when
// a particular data format is found, use a code structure similar to the following.
foreach (string dataFormat in dataFormats)
{
    if (dataFormat == DataFormats.Text)
    {
        // Take some action if/when data in the Text data format is found.
        break;
    }
    else if(dataFormat == DataFormats.StringFormat)
    {
        // Take some action if/when data in the string data format is found.
        break;
    }
}

Remarks

For a set of predefined data formats, see the DataFormats class.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

GetFormats(Boolean)

Returns a list of formats in which the data in this data object is stored. A Boolean flag indicates whether to also include formats that the data can be automatically converted to.

C#
public string[] GetFormats(bool autoConvert);

Parameters

autoConvert
Boolean

true to retrieve all formats in which the data in this data object is stored, or can be converted to; false to retrieve only formats in which the data in this data object is stored.

Returns

String[]

An array of strings, with each string specifying the name of a format supported by this data object.

Implements

Examples

The following example uses this method to get an array of strings denoting only data formats available in a data object (auto-convertible data formats are filtered).

C#
DataObject dataObject = new DataObject("Some string data to store...");

// Get an array of strings, each string denoting a data format
// that is available in the data object.  This overload of GetDataFormats
// accepts a Boolean parameter inidcating whether to include auto-convertible
// data formats, or only return native data formats.
string[] dataFormats = dataObject.GetFormats(false /* Include auto-convertible? */);

// Get the number of native data formats present in the data object.
int numberOfDataFormats = dataFormats.Length;

// To enumerate the resulting array of data formats, and take some action when
// a particular data format is found, use a code structure similar to the following.
foreach (string dataFormat in dataFormats)
{
    if (dataFormat == DataFormats.Text)
    {
        // Take some action if/when data in the Text data format is found.
        break;
    }
}

Remarks

For a set of predefined data formats, see the DataFormats class.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10