3

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.

CDspace
  • 2,639
  • 18
  • 30
  • 36
kmacek
  • 51
  • 6
  • Are you using this on Windows? [The max path size is 255 characters](https://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath) – maccettura Jan 23 '18 at 19:13

1 Answers1

1

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

jpsimard-nyx
  • 8,587
  • 6
  • 32
  • 48
  • Yeah, i see, I can't create directory even manually. Thank you. So the soultion would be to use as short folder names as i can? – kmacek Jan 23 '18 at 19:19
  • Yup! You cannot exceed this limit. – jpsimard-nyx Jan 23 '18 at 19:27
  • This hasn't been true since .NET 4.6.2 was released in August 2016: https://stackoverflow.com/questions/5188527/how-to-deal-with-files-with-a-name-longer-than-259-characters – Ashley Ross Jun 12 '20 at 16:52