sandeep.mishra
sandeep.mishra

Reputation: 825

loading xml file in windows form application giving exception

I added a xml file into my solution in a windows application. but when i am executing the below code it is not finding the xml.

  var xDoc = XDocument.Load("Services.xml");

It is giving exception that this xml is not found inside bin/debug\folder.

Can anybody help me on this..?

Upvotes: 0

Views: 563

Answers (2)

Fᴀʀʜᴀɴ Aɴᴀᴍ
Fᴀʀʜᴀɴ Aɴᴀᴍ

Reputation: 6251

Use:-

var xDoc = XDocument.Load(Application.StartupPath + "\Services.xml");

Apart from that make sure: -

  • The file actually exists.
  • The file name is correct (Case-Sensitivity)
  • You have proper permissions.

Upvotes: 1

Joseph M. Shunia
Joseph M. Shunia

Reputation: 310

As others have mentioned, this is because your XML file is not being copied to your bin/Debug folder.

If your XML file is included in your project folder and you want it to copy over automatically whenever you debug or build, then right click on it within the Solution Explorer and goto Properties. From the Properties menu, set Build Action to "Content" and Copy to Output Directory to "Copy if newer".

Let me know if this doesn't work.

Upvotes: 0

Related Questions