DataObject.GetFormats Method

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

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

public string[] GetFormats()

Return Value

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



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

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

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. 
    else if(dataFormat == DataFormats.StringFormat)
        // Take some action if/when data in the string data format is found. 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft