asp.net网站上传文件 未能找到路径的一部分

2020年10月10日07:10:03 评论 912
首月免费体验

遇到问题:今天测试用户上传照片,发现照片死活上传不上去,该照片上传是根据每个人的用户名为每个用户创建一个属于自己的文件夹。

解决方法:后来检查了一下,发现是因为我没有提前创建该用户的文件夹目录,所以导致照片上传失败。

简单一点直接去新建目录目录即可。

或者添加下面的代码

string CreatePath = context.Server.MapPath("~/SingerPhotos/" + UserDirectory);
if (!Directory.Exists(CreatePath))
{
Directory.CreateDirectory(CreatePath);
}

在保存文件前加上这样一点代码就可以了。

weinxin
博主微信
这是我的微信扫一扫

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: