everyone. I'm developing a small ASP.NET Mvc project in Mono 2.4, Ubuntu 10.10. There is an array of objects, each one of them corresponds to a certain xml file. Reading of the xmls is performed with XmlTextReader. That does not work because xml files have rare "cp866nav" encoding, which is not supported by XmlTextReader ("System.ArgumentException: Encoding name 'cp866nav' not supported
"). But it works fine if encoding in xml heade开发者_运维技巧r is changed to "cp866". I found a kind of solution which consists in initializing XmlTextReader with a StreamReader with a certain encoding instead of file name, like in the code below:
XmlTextReader reader = new XmlTextReader(new StreamReader(Server.MapPath(filename), Encoding.GetEncoding("cp866")));
The issue is that the directory which contains xml files is read only (I can not change it), so I get
"System.UnauthorizedAccessException: Access to the path '' is denied.
". Rather strange, because XmlTextReader initialized with a filename seems to read the files.
Is there any solution, considering that program cannot modify or create files?
As your problem is with file access rather than encoding I'd recommend trying to open file as stream yourslef with correct flags FileStream(name, FileMode.Open, FileAccess.Read) and then calling the other constructor StreamReader that takes Stream.
(Don't forget to dispose stream/readers when you are done).
精彩评论