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
)

Parameters

format
Type: System.String

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

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

Implements

IDataObject.GetDataPresent(String, Boolean)

ExceptionCondition
ArgumentNullException

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.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft