Επεξεργασία

Κοινή χρήση μέσω


DataObject.GetData Method

Definition

Returns data in a specified data format.

Overloads

GetData(String)

Returns data in a format specified by a string.

GetData(Type)

Returns a data object in a format specified by a Type object.

GetData(String, Boolean)

Returns a data object in a specified format, optionally converting the data to the specified format.

GetData(String)

Returns data in a format specified by a string.

public:
 virtual System::Object ^ GetData(System::String ^ format);
public object GetData (string format);
abstract member GetData : string -> obj
override this.GetData : string -> obj
Public Function GetData (format As String) As Object

Parameters

format
String

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

Returns

An object that contains the data in the specified format, or null if the data is unavailable in the specified format.

Implements

Exceptions

format is null.

Examples

The following example uses this method to first check whether a specified data format is available (natively or by auto-convert); if the specified format is available, the example retrieves the data by using the GetData(String) method.

DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// This particular overload of GetDataPresent looks for both native and auto-convertible 
// data formats.
if (dataObject.GetDataPresent(desiredFormat))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}
Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim data() As Byte = Nothing

' Use the GetDataPresent method to check for the presence of a desired data format.
' This particular overload of GetDataPresent looks for both native and auto-convertible 
' data formats.
If dataObject.GetDataPresent(desiredFormat) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If

The following example code uses the GetDataPresent(String, Boolean) method to first check if a specified data format is available natively (auto-convertible data formats are filtered); if the specified format is available, the example retrieves the data by using the GetData(String) method.

DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
bool noAutoConvert = false;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// The autoconvert parameter is set to false to filter out auto-convertible data formats,
// returning true only if the specified data format is available natively.
if (dataObject.GetDataPresent(desiredFormat, noAutoConvert))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}
Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim noAutoConvert As Boolean = False
Dim data() As Byte = Nothing

' Use the GetDataPresent method to check for the presence of a desired data format.
' The autoconvert parameter is set to false to filter out auto-convertible data formats,
' returning true only if the specified data format is available natively.
If dataObject.GetDataPresent(desiredFormat, noAutoConvert) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If

See also

Applies to

GetData(Type)

Returns a data object in a format specified by a Type object.

public:
 virtual System::Object ^ GetData(Type ^ format);
public object GetData (Type format);
abstract member GetData : Type -> obj
override this.GetData : Type -> obj
Public Function GetData (format As Type) As Object

Parameters

format
Type

A Type that specifies the format for the data. For a set of predefined data formats, see the DataFormats class.

Returns

A data object with the data in the specified format, or null if the data is unavailable in the specified format.

Implements

Exceptions

format is null.

See also

Applies to

GetData(String, Boolean)

Returns a data object in a specified format, optionally converting the data to the specified format.

public:
 virtual System::Object ^ GetData(System::String ^ format, bool autoConvert);
public object GetData (string format, bool autoConvert);
abstract member GetData : string * bool -> obj
override this.GetData : string * bool -> obj
Public Function GetData (format As String, autoConvert As Boolean) As Object

Parameters

format
String

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

autoConvert
Boolean

true to attempt to automatically convert the data to the specified format; false for no data format conversion.

Returns

A data object with the data in the specified format, or null if the data is unavailable in the specified format.

If the autoConvert parameter is true and the data cannot be converted to the specified format, or if automatic conversion is disabled (by calling SetData(String, Object, Boolean) with the autoConvert parameter set to false), this method returns null.

Implements

Exceptions

format is null.

See also

Applies to