This documentation is archived and is not being maintained.

DataObject.GetFormats Method (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.

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

public string[] GetFormats(
	bool autoConvert
)
You cannot use methods in XAML.

Parameters

autoConvert
Type: System.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.

Return Value

Type: System.String[]
An array of strings, with each string specifying the name of a format supported by this data object.

Implements

IDataObject.GetFormats(Boolean)

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

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).

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;
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Show: