I am generating an XML file and I want it to be generated by the exe.
XmlTextWriter writer = new XmlTextWriter(@"c:\dados\filmes.xml", null);
instead of per directory to save to the exe.
I am generating an XML file and I want it to be generated by the exe.
XmlTextWriter writer = new XmlTextWriter(@"c:\dados\filmes.xml", null);
instead of per directory to save to the exe.
With this:
string caminho = System.Reflection.Assembly.GetExecutingAssembly().Location;
From there you get the directory where the executable is. You can use the GetDirectoryName
method of the Path
to get the directory.
You can use Environment.CurrentDirectory
:
string caminho = Path.Combine(Enviroment.CurrentDirectory, "filmes.xml");
Extra:
If you have to work with paths, you can use Path.Combine in order to abstract some of the complexity of creating paths correctly.