Accessing clipboard from a C# console application

Simple, but a few non-obvious things required:

1. Add a reference to System.Windows.Forms
2. Add a [STAThread] attribute above the Main method (see here for more information)
3. Now you’re ready to use the methods on Clipboard to write to the clipboard:

using System.Windows.Forms;

namespace MyNamespace
    public class Program
        public static void Main(string[] args)
            Clipboard.SetText("Text to put on the clipboard");

Something to add?

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