0

I trying to create file with more than 260 characters of file path with .Net Framework 4.6.2

This is working fine in Windows 10, but not able to create in Windows 7 environment.

I am trying to create file pragmatically using C#.

Can you please help me to find solution that will work for any Windows environment.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Herin
  • 704
  • 3
  • 18
  • 34
  • Theoretically you can with workarounds, but its more practical to just stick to the 260 character limit (https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath). It's not called a limit for nothing. – Caramiriel Jan 12 '18 at 10:18
  • Yeh but It's working fine with .Net framework 4.6.2 in Win 10 Environment. I have referred this : https://msdn.microsoft.com/en-us/library/system.io.pathtoolongexception(v=vs.110).aspx But It's not working in Win 7 Environment – Herin Jan 12 '18 at 10:23
  • for any Windows environment, stick to the limit – Alex Jan 12 '18 at 10:36
  • Check https://stackoverflow.com/a/1066022/2137237 – Markus Deibel Jan 12 '18 at 10:38
  • Hi Markus, I have followed this : http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx But I need smart way to achieve it in Win 7 Environment – Herin Jan 12 '18 at 10:54
  • You could use my [Zeta Long Paths library](https://github.com/UweKeim/ZetaLongPaths). ([NuGet package](https://www.nuget.org/packages/ZetaLongPaths)) – Uwe Keim Jan 12 '18 at 12:13
  • Also in Windows server 2012 R2 OS, this is not working with more than 260 characters file path, It's giving other error i.e. "System.IO.DirectoryNotFoundException" while creating file with More than 260 characters. Can anyone help me out from this issue ? Thanks. – Herin Jan 18 '18 at 06:24

2 Answers2

1

Windows 7 does not support paths longer than 260 characters. Stick to this limit if you can. Unsupported functionality might break in a Windows update.

You can read more about this here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath This link also explains the '\\?\' prefix which allows paths up to approximately 32'767 characters (Example: "\\?\D:\very long path"). But I haven't tested '\\?\' with the C# API.

The following links might also be interesting

renklus
  • 776
  • 6
  • 17
  • Yes, but the thing will work in Win 10 after upgrading .Net Framework 4.6.2 In Win 7 also I have upgraded .Net Framework 4.6.2, but it's misbehaving in other way. So, what will be best way to achieve it as we can achieve it after .Net Framework upgrade to 4.6.2 – Herin Jan 12 '18 at 10:43
  • @Herin Yes 4.6.2 supports long paths as stated in your link about PathTooLongException. But Win7 doesn't. As stated on the same page PathTooLongException is thrown when the operating system returns a PathTooLong error. Don't expect it to work with Win7. That's not a functionality that was inteded to work with Win7. Just be happy if you find a way to get it to work. – renklus Jan 12 '18 at 11:03
  • Hey Renklus, This is also not working with Windows server 2012 R2 OS. Can you suggest better way to come out from this issue. Thanks. – Herin Jan 18 '18 at 06:22
1

You can use ZetaLongPaths library for older systems and/or frameworks. There are several similar libraries exists, but this one is probably the best.

arbiter
  • 9,447
  • 1
  • 32
  • 43