#720 – Discovering What Kind of Data Is on the Clipboard

You can use one of several static methods in the Clipboard class to find out what type of data is currently on the Windows clipboard.

There are several methods that check for a specific format (ContainsAudioContainsFileDropListContainsImage, and ContainsText).  You can also use the ContainsData method to check for a specific format.

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder sbCB = new StringBuilder();

            // Check for some specific formats
            if (Clipboard.ContainsAudio())
                sbCB.Append("Audio ");

            if (Clipboard.ContainsFileDropList())
                sbCB.Append("FileDropList ");

            if (Clipboard.ContainsImage())
                sbCB.Append("Image ");

            if (Clipboard.ContainsText())
                sbCB.Append("Text ");

            // Can also check for specific formats
            // (See System.Windows.DataFormats for full list)
            if (Clipboard.ContainsData(DataFormats.CommaSeparatedValue))
                sbCB.Append("CommaSeparatedValue ");

            if (Clipboard.ContainsData(DataFormats.EnhancedMetafile))
                sbCB.Append("EnhancedMetafile ");

            lblInfo.Content = "Clipboard contains: " + sbCB.ToString();
        }

720-001
720-002

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: