How to access an application object from a console application?

I took the code from my Windows C # form application, which uses the Application object to get the starting path and tried to use it in a console application. When I did this, the compiler displayed the following msg error - "The name" Applicaiton "does not exist in the current context. Some research was done and it was found that the Application object is in the System.Windows.Forms namespace. Referencing this without a visible effect. Then I tried add using System.Windows.Forms to the beginning of the file and received a new error message - "The type or name of the namespace" Windows "does not exist in the namespace" System "(do you miss the assembly reference?). "Can you shed some light on how to access the application object from the console application?

+3
source share
4 answers

System.Reflection.Assembly.GetExecutingAssembly () Location.

Also, for the desired directory, end the call in System.IO.Path.GetDirectory ()

+6
source

The application is not available for console applications, it is for window forms. you can use

Assembly.GetExecutingAssembly().CodeBase
+2
source

System.Windows.Forms( " ..." ) using System.Windows.Forms . .

0

The method proposed by Denis Biondich is the right way for a console application. But in response to your question, you could do it this way if you added a link to System.Windows in the links to your application. When you select a console application template, this link is not enabled by default, so if you need members from this namespace, you must add a link to the dll.

0
source

All Articles