1 out of 691 rated this helpful Rate this topic

Clipboard Class

Provides static methods that facilitate transferring data to and from the system Clipboard.

System.Object
  System.Windows.Clipboard

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)
public static class Clipboard

The Clipboard type exposes the following members.

  Name Description
Public method Static member Clear Clears any data from the system Clipboard.
Public method Static member ContainsAudio Queries the Clipboard for the presence of data in the WaveAudio data format.
Public method Static member ContainsData Queries the Clipboard for the presence of data in a specified data format.
Public method Static member ContainsFileDropList Queries the Clipboard for the presence of data in the FileDrop data format.
Public method Static member ContainsImage Queries the Clipboard for the presence of data in the Bitmap data format.
Public method Static member ContainsText Queries the Clipboard for the presence of data in the UnicodeText format.
Public method Static member ContainsText(TextDataFormat) Queries the Clipboard for the presence of data in a text data format.
Public method Static member GetAudioStream Returns a stream of Clipboard data in the WaveAudio data format.
Public method Static member GetData Retrieves data in a specified format from the Clipboard.
Public method Static member GetDataObject Returns a data object that represents the entire contents of the Clipboard.
Public method Static member GetFileDropList Returns a string collection that contains a list of dropped files available on the Clipboard.
Public method Static member GetImage Returns a BitmapSource object from the Clipboard that contains data in the Bitmap format.
Public method Static member GetText Returns a string containing the UnicodeText data on the Clipboard.
Public method Static member GetText(TextDataFormat) Returns a string containing text data on the Clipboard.
Public method Static member IsCurrent Compares a specified data object to the contents of the Clipboard.
Public method Static member SetAudio(Byte()) Stores audio data (WaveAudio data format) on the Clipboard. The audio data is specified as a byte array.
Public method Static member SetAudio(Stream) Stores audio data (WaveAudio data format) on the Clipboard. The audio data is specified as a stream.
Public method Static member SetData Stores the specified data on the Clipboard in the specified format.
Public method Static member SetDataObject(Object) Places a specified non-persistent data object on the system Clipboard.
Public method Static member SetDataObject(Object, Boolean) Places a specified data object on the system Clipboard and accepts a Boolean parameter that indicates whether the data object should be left on the Clipboard when the application exits.
Public method Static member SetFileDropList Stores FileDrop data on the Clipboard. The dropped file list is specified as a string collection.
Public method Static member SetImage Stores Bitmap data on the Clipboard. The image data is specified as a BitmapSource.
Public method Static member SetText(String) Stores UnicodeText data on the Clipboard.
Public method Static member SetText(String, TextDataFormat) Stores text data on the Clipboard in a specified text data format. The UnicodeText data to store is specified as a string.
Top

All applications for Windows share the system Clipboard, so the contents are subject to change when you switch to another application.

For a list of predefined formats available to use with the Clipboard class, see the DataFormats class.

Security Alert: For security purposes, the following points should be kept in mind.

  • Paste operations need to be user initiated (Ctrl-V, Paste Menu).

  • Copy can only be on user selected content.

  • On copy or cut, partial trust code puts plaintext and Extensible Application Markup Language (XAML) on to the clipboard. Plaintext includes text, Unicode text, OEM (Object Exchange Model) text, and CSV (Comma-separated values).

  • On paste, Windows Presentation Foundation (WPF) will paste in Extensible Application Markup Language (XAML) if the source of that content is from a equally trusted or more trusted site. Specifically:

    • A partial trust application can paste Extensible Application Markup Language (XAML) from a full trust application.

    • A partial trust application can paste Extensible Application Markup Language (XAML) from a partial trust application.

    • A full trust application can paste XAML only from another fully trusted application.

    • A non-Windows Presentation Foundation (WPF) full trust application can examine the ApplicationTrust format on the clipboard and sanitize the XAML if appropriate.

The following example shows how to add data to the system Clipboard.



// For this example, the data to be placed on the clipboard is a simple
// string.
string textData = "I want to put this string on the clipboard.";

// After this call, the data (string) is placed on the clipboard and tagged
// with a data format of "Text".
Clipboard.SetData(DataFormats.Text, (Object)textData);


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ