找不到路径的一部分“C:\\用户\\ shyful \\桌面\\ MvcApp \\ MvcApp \\人\\上传\\ Jellyfish.jpg” [英] Could not find a part of the path 'C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\Jellyfish.jpg'

查看:243
本文介绍了找不到路径的一部分“C:\\用户\\ shyful \\桌面\\ MvcApp \\ MvcApp \\人\\上传\\ Jellyfish.jpg”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我跑项目,它显示找不到路径的一部分C:\\用户\\ shyful \\桌面\\ MvcApp \\ MvcApp \\人\\上传\\ Jellyfish.jpg。

When i ran the Project ,it shows "Could not find a part of the path 'C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\Jellyfish.jpg'.

说明:在当前Web请求的执行过程中发生未处理的异常。请检查堆栈跟踪有关该错误的详细信息以及它起源于code。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.IO.DirectoryNotFoundException:找不到路径的一部分
'C:\\用户\\ shyful \\桌面\\ MvcApp \\ MvcApp \\人\\上传\\ Jellyfish.jpg

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\Jellyfish.jpg'.

uploadFile.SaveAs(filePatha);
db.image.Add(image);
db.Entry(image).State = EntityState.Modified; 

在哪里是错误的,我code

where's wrong in my code

推荐答案

异常消息:找不到路径的一部分......是 DirectoryNotFoundException

The exception message: "Could not find a part of the path ..." is the message of the DirectoryNotFoundException.

为了救你必须确保该目录第一存在的文件!

In order to save a file you have to ensure that the directory exists first!

运行这个你保存文件之​​前:

Run this before you save the file:

if(!Directory.Exists(@"C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\"))
{
 Directory.CreateDirectory(@"C:\Users\shyful\Desktop\MvcApp\MvcApp\Person\Upload\");
}

这篇关于找不到路径的一部分“C:\\用户\\ shyful \\桌面\\ MvcApp \\ MvcApp \\人\\上传\\ Jellyfish.jpg”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆