"Illegal characters in path" with XmlReader of .Net 1.1

I only found one post on Google where someone mentions the same problem 
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
0
eschwabe (6)
4/28/2006 4:53:27 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
1255 Views

Similar Articles

[PageSpeed] 6

* Eckhard Schwabe wrote in microsoft.public.dotnet.xml:
>I only found one post on Google where someone mentions the same problem 
>with a DataSet:
>
>XmlDataReader in .Net 1.1 can not read XML files from a path which 
>contains "%10" or "%3f".

To clarify, does the path include the string "%3f" or does it include
the string "?"? In case of the former you have to URL-escpae the path
before passing it here, System.Uri has methods for that. "%253f" would
be the right string in this case.

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

The documentation is rather clear that the arguments are URLs, not file
names. There is some overlap, but in cases like this the difference is
important.

>- What is so special about "%10" or "%3f" ? Are there other 
>"problematic" charater combinations?

These map to U+0010 and U+003F, a control character and the question
mark. RFC 3986 has the details.
-- 
Bj�rn H�hrmann � mailto:bjoern@hoehrmann.de � http://bjoern.hoehrmann.de
Weinh. Str. 22 � Telefon: +49(0)621/4309674 � http://www.bjoernsworld.de
68309 Mannheim � PGP Pub. KeyID: 0xA4357E78 � http://www.websitedev.de/ 
0
bjoern1 (135)
4/29/2006 1:12:59 PM
>> XmlDataReader in .Net 1.1 can not read XML files from a path which 
>> contains "%10" or "%3f".
> 
> To clarify, does the path include the string "%3f" or does it include
> the string "?"? 

It includes "%3f".
"?" is an illegal character for a path, so this wouldn't be a bug.

>In case of the former you have to URL-escpae the path
> before passing it here, System.Uri has methods for that. "%253f" would
> be the right string in this case.

I don't understand what you mean.

> The documentation is rather clear that the arguments are URLs, not file
> names. There is some overlap, but in cases like this the difference is
> important.

And why has DotNet 2.0 no problems with the same file name?
 From the Documentation for "DataSet.ReadXml" (which had the same 
problem in DotNet 1.1):

 >DataSet.ReadXml (String)  Reads XML schema and data into the DataSet 
 >using the specified file.

So it clearly states: "file", not "URL".

>> - What is so special about "%10" or "%3f" ? Are there other 
>> "problematic" charater combinations?
> 
> These map to U+0010 and U+003F, a control character and the question
> mark. RFC 3986 has the details.

So DotNet 1.1 erroneously translated "%3f" to a question mark, which IS 
an invalid character before trying to open the file. The bug was perhaps 
in "Urlresolver class"?

Regards,

Eckhard
0
eschwabe (6)
4/30/2006 1:10:25 PM
* Eckhard Schwabe wrote in microsoft.public.dotnet.xml:
>>In case of the former you have to URL-escpae the path
>> before passing it here, System.Uri has methods for that. "%253f" would
>> be the right string in this case.
>
>I don't understand what you mean.

URLs use %xx as escape sequence for special characters. The '%'
character is a special character that has to be escaped if it is
not part of such an escape sequence. %25 is the escape sequence
for the '%' character, %3f is the escape sequence for the '?'
character.

>And why has DotNet 2.0 no problems with the same file name?

The argument is not a file name. .NET 2.0 presumably has code to
work around authoring errors like this.

>So it clearly states: "file", not "URL".

It would be good if you could file a documentation bug report on
this then, e.g. using the "Send comments" link on the MSDN page.
-- 
Bj�rn H�hrmann � mailto:bjoern@hoehrmann.de � http://bjoern.hoehrmann.de
Weinh. Str. 22 � Telefon: +49(0)621/4309674 � http://www.bjoernsworld.de
68309 Mannheim � PGP Pub. KeyID: 0xA4357E78 � http://www.websitedev.de/ 
0
bjoern1 (135)
4/30/2006 5:38:26 PM
Reply:

Similar Artilces:

Illegal characters in path
I'm getting an XML dataset from a web service passed as a string. I then do XmlDocument myXmlDoc = new XmlDocument(); myXmlDoc.Load(mystring); This causes an exception: Illegal characters in string. the string contains <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<validate>\n\t\t\t\t\t<error>\n\t\t\t\t\t\t<message>Login failed</message>\n\t\t\t\t\t</error>\n\t\t\t\t\t<sessionid/>\n\t\t\t\t</validate> Is there something wrong with this string? could those tabs be causing the problem? Is there a utility tester anywhe...

ReadXML Illegal characters in path
Getting error: Illegal characters in path what's wrong with this? string xmlSR = "<XmlDS><table1><phone>Value1</phone><name>jake</name></table1></XmlDS>"; myDataSet.ReadXml(xmlSR, XmlReadMode.IgnoreSchema); DataList5.DataSource = myDataSet; DataList5.DataBind(); Also, what's the best way to return XML from a method for binding into a web control? myDataSet.ReadXml(x.y(), XmlReadMode.IgnoreSchema); I'm trying this, but it's resulting in error about no datasource, also, its only returning the first row: public st...

XML error: Illegal characters in path
Hi, I am using a web service to call an asp page on a remote server via System.Net.WebClient . The asp page returns a xml stream persisted from a recordset. I am having problems converting the stream into a valid xmltextreader document. I have also converted the document to the simple format without the DTD ( just plain xml file ) and I still get the same error: Illegal characters in path. Exception Details: System.ArgumentException: Illegal characters in path. I have pasted to code below: <WebMethod(Description:="passsing ODBC sql str and DSN paramenters. Returns datatable")...

"Illegal characters in path" with XmlReader of .Net 1.1
I only found one post on Google where someone mentions the same problem 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,...