gpt4 book ai didi

c# - 路径中的哈希字符抛出 DirectoryNotFoundException

转载 作者:太空宇宙 更新时间:2023-11-03 19:37:55 24 4
gpt4 key购买 nike

考虑以下代码片段

private void ProcessFile(string fullPath) {
XmlTextReader rdr = new XmlTextReader("file:\\\\" + fullPath);
while (rdr.Read()) {
//Do something
}
return;
}

现在,当传递如下路径时,此功能正常:

"C:\Work Files\Technical Information\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(字符串路径、FileMode 模式、FileAccess 访问、Int32 权限、Boolean useRights、FileShare 共享、Int32 bufferSize、FileOptions 选项、SECURITY_ATTRIBUTES secAttrs、String msgPath、Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
在 System.Xml.XmlDownloadManager.GetStream(Uri uri,ICredentials 凭据)
在 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri,字符串角色,ObjectToReturn 类型)
在 System.Xml.XmlTextReaderImpl.OpenUrlDelegate(对象 xmlResolver)
在 System.Threading.CompressedStack.runTryCode(Object userData)
在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode 代码,CleanupCode backoutCode,Object userData)
在 System.Threading.CompressedStack.Run(CompressedStack compressedStack,ContextCallback 回调,对象状态)
在 System.Xml.XmlTextReaderImpl.OpenUrl()
在 System.Xml.XmlTextReaderImpl.Read()
在 System.Xml.XmlTextReader.Read() 处

有人知道这是怎么回事吗?

最佳答案

添加到 Konrad 的回答中,如果您使用的是 file://协议(protocol),则需要为 # 使用 %23 才能正常工作

关于c# - 路径中的哈希字符抛出 DirectoryNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/221224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com