路径长度超过260个字符时发生System.IO.DirectoryNotFoundException [英] System.IO.DirectoryNotFoundException when path is longer than 260 characters

查看:68
本文介绍了路径长度超过260个字符时发生System.IO.DirectoryNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ASP.NET Core MVC项目(目标是.NET 4.62),我正在尝试保存文件.当路径的长度小于260(或者我不确定248)时,一切正常,但是当路径的长度更长时,我得到一个 System.IO.DirectoryNotFoundException .以前,当我定位.NET 4.61时,我遇到了Path太长异常的情况,我已经读到该问题在.NET 4.62中已解决,但不适用于我.

I have ASP.NET Core MVC project (targeting .NET 4.62) and I'm trying to save files. Everything works while the length of the path is under 260 (or 248 I'm not sure), but when it's longer I get a System.IO.DirectoryNotFoundException. Previously when I was targeting .NET 4.61 I was getting Path too long exception, I've read that the problem is fixed in .NET 4.62 but not for me.

这里是我在路径太长时得到的一个例外

Here's exception that I'm getting while path is too long

File.Copy(file, Path.Combine(path, dbFile.Id.ToString()));

我很确定该目录存在.

推荐答案

我为您介绍了

I refer you to this answer on why the ~255 limit filename|folder. Probabaly a probleme because you are on Windows on NTFS. Nothing to do with .NET framework

这篇关于路径长度超过260个字符时发生System.IO.DirectoryNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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