DataObject.GetDataPresent Method (String, Boolean)

Determines whether the data is available in, or can be converted to, a specified format. A Boolean flag indicates whether to check if the data can be converted to the specified format if it is not available in that format.

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

public bool GetDataPresent(
	string format,
	bool autoConvert


Type: System.String

A string that specifies the data format to check. For a set of predefined data formats, see the DataFormats class.

Type: System.Boolean

false to check only for the specified format; true to also check whether data stored in this data object can be converted to the specified format.

Return Value

Type: System.Boolean

true if the data is in, or can be converted to, the specified format; otherwise, false.


IDataObject.GetDataPresent(String, Boolean)


format is null.

Call GetDataPresent to determine whether a format is available in this data object before calling GetData. Call GetFormats to obtain a list of all the formats that are available in this data object.

The following example uses this method to query for data by descriptor string, and specifies how to treat auto-convertible data formats.

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

// Query for the presence of Text data in the data object, by data format descriptor string, 
// and specifying whether auto-convertible data formats are acceptable.   

// In this case, Text data is present natively, so GetDataPresent returns "true".
string textData = null;
if (dataObject.GetDataPresent(DataFormats.Text, false /* Auto-convert? */))
    textData = dataObject.GetData(DataFormats.Text) as string;

// In this case, the Text data in the data object can be autoconverted to  
// Unicode text, but it is not available natively, so GetDataPresent returns "false".
byte[] unicodeData = null;
if (dataObject.GetDataPresent(DataFormats.UnicodeText, false /* Auto-convert? */))
    unicodeData = dataObject.GetData(DataFormats.UnicodeText) as byte[];

// In this case, the Text data in the data object can be autoconverted to  
// Unicode text, so GetDataPresent returns "true".
if (dataObject.GetDataPresent(DataFormats.UnicodeText, true /* Auto-convert? */))
    unicodeData = dataObject.GetData(DataFormats.UnicodeText) as byte[];

.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