You can know which is the path in which the context of the application is running by looking at BaseDirectory
of AppDomain
.
AppDomain.CurrentDomain.BaseDirectory
What you say about the file .txt
I did not understand it very well, but if it is in the same directory as the .exe
of the application, the case would be the same.
If not, to open it you need the path beforehand, so I'm not sure what would be the case that you need to control beyond the BaseDirectory
.
EDITED:
Based on the comments, I add this other answer to recover the path of the file.
When you create a file association in Windows, basically what you do is send it as an argument by command line.
To recover it, you simply have to recover that argument
static void Main(string[] args)
{
IList<string> ficheros = new List<string>();
foreach (string fichero in args)
{
ficheros.Add(fichero);
}
}
With this code in the main main what we do is recover all the arguments that are passed to our executable (presumably file paths) and fill a list with these parameters.
If you only want to open a file every time and do not support opening several files at once, you simply need to recover the first parameter:
static void Main(string[] args)
{
string fichero = null;
if(args.Length > 0)
{
fichero = args[0];
}
}