I need to write a file in the same folder where a console ClickOnce .application (executable file) resides. The folder where it launches from.
I tried u
I'm using Assembly.GetExecutingAssembly().Location to get the path to a ClickOnce deployed application in .Net 4.5.1.
However, you shouldn't write to any folder where your application is deployed to ever, regardless of deployment method (xcopy, ClickOnce, InstallShield, anything) because those are usually read only for applications, especially in newer Windows versions and server environments.
An app must always write to the folders reserved for such purposes. You can get the folders you need starting from Environment.SpecialFolder Enumeration. The MSDN page explains what each folder is for: http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx
I.e. for data, logs and other files one can use ApplicationData (roaming), LocalApplicationData (local) or CommonApplicationData.
For temporary files use Path.GetTempPath or Path.GetTempFileName.
The above work on servers and desktops too.
EDIT:
Assembly.GetExecutingAssembly() is called in main executable.