I want to use an xml file in a windows forms application. I added a new xml file to my project. When I reference the file like this xmlDataDoc.DataSet.ReadXml("~\TestLog.xml"); how do i just tell it to look at the xml file that is part of the project? The line I put above doesn’t work.
I want to use an xml file in a windows forms application. I added
Share
This will very much depend on the type of application. In ASP.NET application assuming the file is deployed on the site root you could use this:
In a console application, assuming you copy the file to the output folder (
Copy to Output Directory:Copy Alwaysin the properties of the file) at the same place as the executable you could use a relative path:To get the location of the currently executing assembly you could use this:
and then construct a path relative to this location:
So many ways of achieving the same thing, which one to choose depends on your context.