with a DataSet:
XmlDataReader in .Net 1.1 can not read XML files from a path which
contains "%10" or "%3f".
code to reproduce:
string filename = "%10.xml"; //XML file with this name is existing
XmlReader reader = new XmlTextReader(filename);
reader.Read();
this will throw an
System.ArgumentException: "Illegal characters in path."
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.GetFileName(String path)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials
credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role,
Type ofObjectToReturn)
at System.Xml.XmlTextReader.CreateScanner()
at System.Xml.XmlTextReader.Init()
at System.Xml.XmlTextReader.Read()
All classes which use the XmlReader internally have the same problem
(DataSet, XmlDocument, ...), but XmlWriter can write to such a file.
This bug is fixed in .Net 2.0, and in 1.1 the workaround is simply to
first load the file into a streamreader:
IO.StreamReader streamReader = new StreamReader(filename);
XmlReader reader = new XmlTextReader(streamReader);
....
What really interests me is:
- Why can't I find any info about this behaviour on MSDN? This would
have saved us from shipping a product which falls over "%" in the filename.
As our product is for chemists, the probability of choosing this
character in a file or directory name is not so low as one might expect
from "normal" usage: "EtOH60%10ml_method" beeing one example.
- What is so special about "%10" or "%3f" ? Are there other
"problematic" charater combinations?
as a sidenote:
If I try to add a file to a Solution in Visual Studio 2005 it tells me:
Item and file names cannot:
- contain any of the following characters: / ? : & \ * " < > | # %
Since when are "#" or "%" invalid characters in the windows file system?
Eckhard