Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Clipboard.ContainsData Method

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
)
You cannot use methods in XAML.

Parameters

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.

ExceptionCondition
ArgumentNullException

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;
if(IsHTMLDataOnClipboard)
{

    htmlData = Clipboard.GetText(TextDataFormat.Html);

}

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

Community Additions

ADD
Show:
© 2015 Microsoft