4
I am generating an XML file and I want it to generate with exe.
XmlTextWriter writer = new XmlTextWriter(@"c:\dados\filmes.xml", null);
instead of putting the directory to save with exe.
4
I am generating an XML file and I want it to generate with exe.
XmlTextWriter writer = new XmlTextWriter(@"c:\dados\filmes.xml", null);
instead of putting the directory to save with exe.
4
Can use Environment.CurrentDirectory
:
string caminho = Path.Combine(Enviroment.CurrentDirectory, "filmes.xml");
Extra:
If you have to work with paths please use the Path.Combine in order to abstract some of the complexity of creating paths correctly.
4
Thereby:
string caminho = System.Reflection.Assembly.GetExecutingAssembly().Location;
Then you get the directory where the executable is. You can use the method GetDirectoryName
class Path
to get the directory.
This is the only reliable solution to the question. Other ways can work by coincidence. The day the coincidence ends, no one knows why the show blew up.
@bigown however, if the file is a shadow copy, the returned path will be the copy path (MSDN)
Browser other questions tagged c#
You are not signed in. Login or sign up in order to post.
Thank you both for the answer, but one way that solved was by the "." ex: ". .xml file" and it generates together with the executable, I am using Visual Studio, but I think it is a particularity of the language.
– Bruno Rodrigues
@Brunorodrigues tb is a solution, in this case using the point is to create a relative path. My solution and Renan’s would create absolute paths. Nothing wrong with that as long as what you’re using to create the file understands relative paths.
– Omni