考虑以下代码片段
private void ProcessFile(string fullPath) {
XmlTextReader rdr = new XmlTextReader("file:\\\\" + fullPath);
while (rdr.Read()) {
//Do something
}
return;
}
现在,当传递如下路径时,此功能正常:
“C:\工作文件\技术信息\Dummy.xml”
但是通过时会抛出错误
"C:\Work Files\#Technical Information\Dummy.xml"
请注意,指定的所有文件夹和文件都存在,并且哈希字符是路径的有效字符。错误详情如下:
System.IO.DirectoryNotFoundException:找不到路径“C:\Work Files\”的一部分。
在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs , String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System。
System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver
) 处的 Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn
)
在 System.Threading.CompressedStack.runTryCode(Object userData)
在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode 代码, CleanupCode backoutCode, Object userData)
在 System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
在 System.Xml.XmlTextReaderImpl.OpenUrl()
在 System.Xml.XmlTextReaderImpl.Read()
在 System.Xml.XmlTextReader.Read()
有人知道发生了什么吗?