Clipboard.ContainsData Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Queries the Clipboard for the presence of data in a specified data format.

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

public static bool ContainsData(
	string format


Type: System.String

The format of the data to look for. See DataFormats for predefined formats.

Return Value

Type: System.Boolean

true if data in the specified format is available on the Clipboard; otherwise, false. See Remarks.

Exception Condition

format is null.

A query for the data format Bitmap or FileDrop will return true if the data can be automatically converted to the specified data format. For other data formats, this method returns true only if the specified format is available natively on the Clipboard.

The following example demonstrates the use of this method.

// After this line executes, IsHTMLDataOnClipboard will be true if
// HTML data is available natively on the clipboard; if not, it 
// will be false.
bool IsHTMLDataOnClipboard = Clipboard.ContainsData(DataFormats.Html);

// If there is HTML data on the clipboard, retrieve it.
string htmlData;

    htmlData = Clipboard.GetText(TextDataFormat.Html);


.NET Framework
Available since 3.0
Return to top