none
XPathDocument and dots in filename RRS feed

  • Question

  • I open an xml document with the class XmlTextReader:

    XmlTextReader xmlReader = new XmlTextReader("hello.com.hwx");
    xmlReader.XmlResolver = null;
    
    XPathDocument doc = new XPathDocument(xmlReader);
    => exception file not found

    The operation works fine with "hello.hwx". But ".com" in the filename is raising an exception.

    Can someone confirm this behaviour?


    • Edited by Tron 42 Tuesday, October 15, 2013 2:59 PM
    Tuesday, October 15, 2013 2:59 PM

Answers

  • Seems to work, if the file is located in current directory. To avoid problems with paths, try specifying the full path, like ‘new XmlTextReader(@"file://C:\MyFiles\hello.com.hwx")’. If the file is always located in the folder of your program, then you can for example make the full path taking into consideration Application.StartupPath, using Path class etc.

    • Marked as answer by Tron 42 Tuesday, October 15, 2013 8:03 PM
    Tuesday, October 15, 2013 7:16 PM

All replies

  • Seems to work, if the file is located in current directory. To avoid problems with paths, try specifying the full path, like ‘new XmlTextReader(@"file://C:\MyFiles\hello.com.hwx")’. If the file is always located in the folder of your program, then you can for example make the full path taking into consideration Application.StartupPath, using Path class etc.

    • Marked as answer by Tron 42 Tuesday, October 15, 2013 8:03 PM
    Tuesday, October 15, 2013 7:16 PM
  • I was about to remove this question. I was chasing the side effects of a false exception handling. The real and correct exception was "Invalid character in the given encoding". I found the flaw in the XML file that was somehow malformed UTF-8. My apologies to you for this false alarm.
    • Edited by Tron 42 Tuesday, October 15, 2013 8:14 PM
    Tuesday, October 15, 2013 8:13 PM