Search code examples
c#asp.netasp.net-core.net-framework-version

System.IO.DirectoryNotFoundException when path is longer than 260 characters


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

img1

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

I'm pretty sure that directory exists.


Solution

  • 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