File.OpenRead()中文路径出错

ScytheV 2009-12-19 03:28:15
程序运行到FileStream fs = File.OpenRead(filePath);时出错,filePath为中文路径。

出错信息:
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Step into: Stepping over method without symbols 'System.Web.UI.Page.ProcessRequestMain'
A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll
Step into: Stepping over method without symbols 'System.Web.UI.Page.ProcessRequest'
A first chance exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll
Step into: Stepping over method without symbols 'System.Web.UI.Page.ProcessRequest'
Step into: Stepping over method without symbols 'System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute'
Step into: Stepping over method without symbols 'System.Web.HttpApplication.ExecuteStep'
Step into: Stepping over method without symbols 'System.Web.HttpApplication.PipelineStepManager.ResumeSteps'
Step into: Stepping over method without symbols 'System.Web.HttpApplication.BeginProcessRequestNotification'
Step into: Stepping over method without symbols 'System.Web.HttpRuntime.ProcessRequestNotificationPrivate'
Step into: Stepping over method without symbols 'System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper'
Step into: Stepping over method without symbols 'System.Web.Hosting.PipelineRuntime.ProcessRequestNotification'
Step into: Stepping over method without symbols 'System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper'
Step into: Stepping over method without symbols 'System.Web.Hosting.PipelineRuntime.ProcessRequestNotification'
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll


请问怎样用FileStream读取中文路径的文件?
...全文
854 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
rollthewong 2009-12-19
  • 打赏
  • 举报
回复
嘿,奇怪了哈,我用桌面上的图片就不行,用别的地方的就行。

看来不是中文的问题。

谢谢大家~我平均给分了。
hhc123 2009-12-19
  • 打赏
  • 举报
回复
strfilePath = Server.MapPath(strfilePath);
FileStream fs1 = new FileStream(strfilePath);
你用这样的试试看
rollthewong 2009-12-19
  • 打赏
  • 举报
回复
另外,我按照楼上(hujun1024)的建议加入strfilePath = Server.MapPath(strfilePath); 跟踪时运行到此处就出错跳出。
rollthewong 2009-12-19
  • 打赏
  • 举报
回复
确保英文可以。

他的上文是从web.config取得数据库连接字串,就一句话,我跟踪的时候是从FileStream这句话跳出来的。

跟踪的时候filePath为C:\\user\\desktop\\新建文件夹\\大螺旋星系123.jpg,文件是我用文件选择控件从对话框里选的,肯定存在。
hujun1024 2009-12-19
  • 打赏
  • 举报
回复
strfilePath = Server.MapPath(strfilePath);

if(File.Exists(strfilePath))
{
FileStream fs = File.OpenRead(strfilePath);
}

最好不要用中文作为路径,XP下访问没有问题,但在2003下会出错
sageking2 2009-12-19
  • 打赏
  • 举报
回复
这些信息很难判断哪里有问题,最好提供更多上文。跟踪下filePath的内容是什么!
silentwins 2009-12-19
  • 打赏
  • 举报
回复
确保英文可以?

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧