I have a form exe. now on button click i want it to save a file to where it has been opened from, e.g. if i give this exe to you and you copy it to c
myVar.Save(@"test.xml");
This should write test.xml to the directory your exe runs from.
Note that in case of writing to c:\ root folder might require elevated administrator permissions.
You didn't specify the type of myVar, but this might be helpful:
using System.IO;
class Program
{
static void Main(string[] args)
{
File.WriteAllText("HelloWorld", "test.txt");
}
}
This creates test.txt file with HelloWorld content, the file is saved in the executable
directory.