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
You can have a look at using AppDomain.BaseDirectory Property
Gets the base directory that the assembly resolver uses to probe for assemblies.
You also need to look at using Path.Combine Method (String, String)
Combines two strings into a path.
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.