Nicolas Raoul
Nicolas Raoul

Reputation: 60213

C# I/O library that supports long paths (to solve PathTooLongException)

My open source software synchronizes a remote folder to the local desktop. The remote folder can be on Alfresco, where path length has no limit (/root/very/very/very/long/name.txt).

When developing the application I used System.IO.File.OpenWrite and System.IO.Stream.Write, but it appears that they don't support paths over a few hundred characters, so users report errors like PathTooLongException when working with long paths.

UNC paths must absolutely be avoided, because they lead to incompatibility with some applications.

What library/code should be used in this case?

It must be open source C#.

Upvotes: 4

Views: 3889

Answers (5)

Nicolas Raoul
Nicolas Raoul

Reputation: 60213

AlphaFS lets you use very long paths (using the "\?\" style) and mimics the System.IO namespace.

You will probably be able to use this library just as if you were using System.IO. For example, AlphaFS.Win32.Filesystem.File.Copy() instead System.IO.File.Copy().

(source)

Upvotes: 3

Oliver
Oliver

Reputation: 45101

You can try the Base Class Libraries Long Path implementation. But be aware that not everything will work if you start to mix up with default .NET I/O methods.

Upvotes: 2

Nicolas Raoul
Nicolas Raoul

Reputation: 60213

Native File System Access

Since the revision 185 (February 19th, 2013), the library is covered by Microsoft Public License (MS-PL), as specified in the headers of the source code files.

Looks promising, but author advises against using it in an enterprise environment, since the code is not solid enough.

This library has some unit tests, but lacks documentation.

Upvotes: 1

markoo
markoo

Reputation: 738

You could try splitting the path up by using relative paths as outlined in this answer using:

Directory.SetCurrentDirectory()

PathTooLongException in C# code

Upvotes: 1

Nicolas Raoul
Nicolas Raoul

Reputation: 60213

".NET 2.0 Workaround for PathTooLongException" (article+code).

Licensed under The Code Project Open License (CPOL), which is not open source apparently.

Only 2 commits do not make for a very active project, though...

Upvotes: 1

Related Questions