Answered FileNotFoundException

tdignan87

Well-known member
Joined
Jul 8, 2019
Messages
95
Programming Experience
Beginner
Hi
Hoping someone can give me a wee hand.
I have a XML file, that i am adding some new elements then saving as another XML but debugging shows the application cant find the file.
The file is there in the correct path,

Any ideas?

C#:
        try
            {
                XDocument xmlDocument = XDocument.Load(@"C:\Stevens\Integration Service\ConvertPO\PO.xml");
                XDocument result = new XDocument(
                    new XElement("Stevens",
                    new XElement("purchaseOrders",
                    from s in xmlDocument.Descendants("Orders")
                    select new XElement("createdDate", new XElement("purchaseOrders", s.Element("createdTime").Value)))));

                result.Save(@"C:\Stevens\Integration Service\ConvertPO\\POAMENDED.xml");
                Console.ReadLine();
            }
            catch (System.IO.FileNotFoundException e)

            {
                Console.WriteLine(e.ToString());
                Console.ReadLine();
            }


1583253859315.png



Cheers
Tom
 
1583253968509.png

Look very closely at the quoted filename and the filename from Explorer.
 
Look on the bright side: You were a smart developer and actually turned off the Windows default to hide file extensions. You saved yourself a couple of hours right there.
 
Admittedly, I didn't see it at first. I sometimes use a 50" screen at home though, so the pixel of two dots almost looks like one on my screen because the pixels are so small, and the default font doesn't help. But yea, I always have extensions on in folders that i work in just so I can easily avoid problems like this one. Screenshot
 
Back
Top Bottom