The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,708 other followers

.NET/C#: PasteText command line tool as reverse of Clip.exe

Posted by jpluimers on 2015/12/15

Quite a while ago I learned about the clip.exe tool.

clip.exe is a nifty tool that allows you to copy console text output to the clipboard. Though shipping with Windows Server 2003, it wasn’t part of Windows XP, but as of Windows Vista it shipped on desktop versions of Windows.

Digging a bit deeper, I found out it was already part of the Windows NT 4 Resource Kit.

So I wrote PasteText:

PasteText: the reverse of clip.exe; pastes Clipboard.GetText() or Clipboard.GetFileDropList() to the standard output.

The full source code is below and in my repository.

There are many examples on the internet about Clipboard.GetText, but there is very little about Clipboard.GetFileDropList.

It returns a good old System.Collections.Specialized.StringCollection which was introduced in the .NET 1.x era before generic lists were involved. Though its IEnumerable.GetEnumerator returns an IEnumerator instance that has a Current property providing an Object for the loop, that Object is in fact a string. That’s why it also has a GetEnumerator method that returns a StringEnumerator with a Current property providing a string for the loop.

So there is no foreach automatic casting needed: a standard foreach loop will get the string items out of the StringCollection:

For the help text, it uses the verbatim string literal feature that allows you to have a multi-line string literal in C# by prepending it with an @-sign:


PS: Until after I completed PasteText and PasteFiles (more on PasteFiels later), I found out that Rhys Parry wrote a Paste.exe similar to my PasteText on his i-think Twenty-Two blog with a partially different style (he favours var over explicit types, and I favour explaining variables over compound expressions).

And then I found about the old new thing writing about clip, and the gclip and pclip tools.

PasteText.cs sourcecode:

Leave a Reply

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

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: