Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy empty string using Clipboard.SetText(string)

Tags:

c#

clipboard

Clipboard.SetText("") throws me an error - "Value cannot be null". So how do I copy an empty string using Clipboard.SetText?

I have already done Clipboard.Clear(). It does clear the clipboard, but it doesn't help me to paste an empty string

Any suggestions?

like image 241
Sandeep Avatar asked Aug 14 '12 13:08

Sandeep


3 Answers

If you try to save null or an empty string using Clipboard.SetText it will never work.

See Clipboard.SetText Method (String) (MSDN). It mentions ArgumentNullException is thrown if the text is null or Empty for Clipboard.SetText.

Hence you cannot achieve what you are trying to achieve.

like image 55
Bull Avatar answered Nov 12 '22 01:11

Bull


I think you need to do

Clipboard.Clear()

From MSDN

Clears any data from the system Clipboard.

like image 26
parapura rajkumar Avatar answered Nov 12 '22 00:11

parapura rajkumar


See Clipboard.Clear Method (System.Windows.Forms) (MSDN).

Clipboard.Clear();

will clear the clipboard, so you will "paste" an empty string.

like image 4
JleruOHeP Avatar answered Nov 12 '22 00:11

JleruOHeP