0

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..?

2
  • 1
    Have you made sure that the document is located in the exact path that the relative path given points to? Compare the path in the error message with the absolute path of the document, they shouldn't match right now. Commented Aug 17, 2015 at 13:34
  • Are you providing the correct path? Or is the file actually in the bin/debug folder (as the code requests)? Commented Aug 17, 2015 at 13:35

2 Answers 2

1

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.
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.