Search code examples
c#clipboard

I'm using Clipboard.GetDataObject(); but sometimes it does not function like I need


This is the function I'm using

    public String ClipboardGet()
    {
        IDataObject dataObj = Clipboard.GetDataObject();

        if (!dataObj.GetDataPresent(DataFormats.Text))
            return "";

        return dataObj.GetData(DataFormats.Text).ToString();
    }

but sometimes it returns a empty string even when the data is text, how to handel this?


Solution

  • Have you tried Clipboard.GetText or IDataObject.GetDataPresent(string, bool)?