1

I have added an XML file (File.xml) into a project (I can see it in the Solution Explorer), it resides at the root directory level of the project i.e. the same level as the VB program (.vb), the bin directory and the References directory etc..

I try accessing it using XmlDocument.Load("File.xml") ... but it doesn't find it. I get

A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Xml.dll

Any idea where the file is or how I 'address' it?

Thanks for any help

Oliver

LenseOnLife
  • 179
  • 1
  • 7
  • 16
  • Zarkos' answer is the solution. The key is to change publish status to: 'Include'. Whenever we publish our application, It creates two folders. One of them is the application data, the other is for the program. Commonly, the XML file is located in the first folder. The error is because our application attempts to find in the second folder, where clearly the XML file doesn't exists. After changing the public status to `include`, the application will now seek for the XML in the second folder. Beside this, I don't know how to instruct the application to look for the data folder directly . – Arman Nov 01 '13 at 21:54

3 Answers3

3

Is the file copied to the output directory? Click on the file, look at the properties in the VS editor, and set the "Build Action" to Content and "Copy to Output Directory" to either "Copy always" or "Copy if newer" (depending on what you need).

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • Hi, did those changes and it now works OK in debug mode but not when I 'publish' the project. The files are in the relevant package directory within 'Application Files' for the release along with the application .... but not being found. Does the setup put data files in a different directory? – LenseOnLife May 16 '11 at 23:42
  • That I don't know, I don't have experience with setup and publishing applications. You can try the other build actions to see if it makes any difference, or you can also wait for another response. – carlosfigueira May 16 '11 at 23:54
1

In the Publish property go to

Application Files --> Look for the XML file: If the publish status = Data File, then the File will be copied to the Application DATA folder.

If you want the xml to be inside the programs directory change the publish status to: Include.

This will do the trick.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Zarkos
  • 457
  • 10
  • 30
0

Try this:

XmlDocument.LoadXml(System.IO.Path.GetFullPath(Application.StartupPath & "\File.xml"))

It's worth a shot I guess. My question: is it possible to edit a file that's placed in the project?

Donald.Record
  • 301
  • 3
  • 7