JayT JayT - 4 months ago 12
C# Question

Clipboard does not exist in the current content

I want to use

Clipboard.GetText()
in a console application. But I get the error message " The name 'Clipboard' does not exist in the current content". I searched the other questions about it and added
[STAThread]
but the problem is not being solved.

namespace Get_Text_Console_App
{

class Program
{
[STAThread]
static void Main(string[] args)
{
if (Clipboard.ContainsText())
{
string text = Clipboard.GetText();

}
}
}
}

Answer

Add to reference a namespace:

using System.Windows.Forms;

I tried this before. But I think I had to right click on Solution Explorer -> Add -> Reference -> System.Windows.Forms before adding the line to my code. I wonder if so but now it is working :) ...always hard in the beginning. Every little step goes sooooo slowly.