Export (0) Print
Expand All

Clipboard.SetDataObject Method (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.

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

public static void SetDataObject(
	Object data,
	bool copy
)

Parameters

data
Type: System.Object

A data object (an object that implements IDataObject) to place on the system Clipboard.

copy
Type: System.Boolean

true to leave the data on the system Clipboard when the application exits; false to clear the data from the system Clipboard when the application exits.

ExceptionCondition
ArgumentNullException

data is null.

ExternalException

An error occured when accessing the Clipboard. The exception details will include an HResult that identifies the specific error; see ErrorWrapper.ErrorCode.

DataObject provides a basic implementation of the IDataObject interface. IsCurrent determines the data object previously placed on the clipboard by the last SetDataObject call.

The following example demonstrates the use of this method.


// 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.";
// The example will enable auto-conversion of data for this data object. 
bool autoConvert = true;

// Create a new data object, specifying the data format, data to encapsulate, and enabling 
// auto-conversion services.
DataObject data = new DataObject(DataFormats.UnicodeText, (Object)textData, autoConvert);

// If the data to be copied is supposed to be persisted after the application ends,  
// then set the second parameter of SetDataObject to true. 
if(persistentData)
{
    // Place the persisted data on the clipboard.
    Clipboard.SetDataObject(data, true);
}
else
{
    // Place the non-persisted data on the clipboard.
    Clipboard.SetDataObject(data, false);
}

// If you keep a copy of the source data object, you can use the IsCurrent method to see if 
// the data object is still on the clipboard. 
bool isOriginalDataObject = Clipboard.IsCurrent(data);

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • UIPermission 

    for permission to access data on the system Clipboard. Associated enumeration: AllClipboard.

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.

Show:
© 2014 Microsoft