Chessar.LongPaths 1.1.8

Chessar.LongPaths is a .NET library that allows you to enable long path support for the main System.IO classes (and others).
It is based on replacing with JMP hooks, internal functions in System.IO.Path (NormalizePath and GetFullPathInternal), which adds prefixes (\\?\ or \\?\UNC\) for paths to files/folders.
In this case, your code does not need to directly add such prefixes to the paths.

Supported platforms:
 .NET Framework 4.6.2+

Install-Package Chessar.LongPaths -Version 1.1.8
dotnet add package Chessar.LongPaths --version 1.1.8
<PackageReference Include="Chessar.LongPaths" Version="1.1.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chessar.LongPaths --version 1.1.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Version Downloads License Platforms Language Coverage

Chessar.LongPaths is a .NET library that allows you to enable long path support for the main System.IO classes:

FileStream, File, FileInfo, Directory, DirectoryInfo, ... (and others).

The library is based on replacing the internal NormalizePath and GetFullPathInternal functions from the static Path class. The replacement is done using JMP hooks (thanks to @wledfor2), in which the long path prefix \\?\ or \\?\UNC\ is added. Adding a prefix is done by calling the internal function Path.AddLongPathPrefix. Note also that the addition of such prefixes depends on the UseLegacyPathHandling and BlockLongPaths settings, which must necessarily be false (in the AppContextSwitchOverrides element).

In this case, your code does not need to directly add such prefixes to the paths.

Supported Platforms:

How to use

  1. Add the Chessar.LongPaths NuGet package to the project.
  2. In the file app.config (or web.config), in the section runtime, add:
<configuration>
...
  <runtime>
    <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
  </runtime>
...
  1. In the code (when you start the application or at the beginning of Main) add code:
...
using static Chessar.Hooks;
...

    PatchLongPaths();
  1. Usage
...
var fileInfo = new FileInfo(path);
var fullName = fileInfo.FullName; // with long path prefix
...
  1. At the end of the application:
    RemoveLongPathsPatch();

See also Examples.

Notes

Next methods does not work for long paths, even if a prefix is added:

  1. For the following methods:
...
using static Chessar.Hooks;
...

    var di = new DirectoryInfo(...);
    di.MoveTo(path.AddLongPathPrefixAndFixSeparators());

TODO

  1. Add long path support in methods from Notes.
  2. Make hooks more thread safe.

License

MIT - See LICENSE

Version Downloads License Platforms Language Coverage

Chessar.LongPaths is a .NET library that allows you to enable long path support for the main System.IO classes:

FileStream, File, FileInfo, Directory, DirectoryInfo, ... (and others).

The library is based on replacing the internal NormalizePath and GetFullPathInternal functions from the static Path class. The replacement is done using JMP hooks (thanks to @wledfor2), in which the long path prefix \\?\ or \\?\UNC\ is added. Adding a prefix is done by calling the internal function Path.AddLongPathPrefix. Note also that the addition of such prefixes depends on the UseLegacyPathHandling and BlockLongPaths settings, which must necessarily be false (in the AppContextSwitchOverrides element).

In this case, your code does not need to directly add such prefixes to the paths.

Supported Platforms:

How to use

  1. Add the Chessar.LongPaths NuGet package to the project.
  2. In the file app.config (or web.config), in the section runtime, add:
<configuration>
...
  <runtime>
    <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
  </runtime>
...
  1. In the code (when you start the application or at the beginning of Main) add code:
...
using static Chessar.Hooks;
...

    PatchLongPaths();
  1. Usage
...
var fileInfo = new FileInfo(path);
var fullName = fileInfo.FullName; // with long path prefix
...
  1. At the end of the application:
    RemoveLongPathsPatch();

See also Examples.

Notes

Next methods does not work for long paths, even if a prefix is added:

  1. For the following methods:
...
using static Chessar.Hooks;
...

    var di = new DirectoryInfo(...);
    di.MoveTo(path.AddLongPathPrefixAndFixSeparators());

TODO

  1. Add long path support in methods from Notes.
  2. Make hooks more thread safe.

License

MIT - See LICENSE

Release Notes

Fixed enumerating of FS items for a drive letter

  • .NETFramework 4.6.2

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.8 260 10/25/2018
1.1.7 231 10/2/2018
1.1.7-rc003 171 10/2/2018
1.1.6 197 9/24/2018
1.1.5 187 9/23/2018
1.1.4 213 9/21/2018
1.1.3 191 9/20/2018
1.1.2 194 9/16/2018
1.1.1 207 9/12/2018
1.1.0 202 9/10/2018
1.0.9 235 9/4/2018
1.0.8 223 8/26/2018
1.0.7 249 7/30/2018
1.0.6 235 7/25/2018
1.0.5 242 7/19/2018
1.0.4 275 7/18/2018
1.0.3 291 7/18/2018
1.0.2 288 7/18/2018
1.0.1 286 7/12/2018
1.0.0 290 7/12/2018
1.0.0-rc005 217 7/5/2018
1.0.0-rc004 273 6/20/2018
1.0.0-rc003 276 6/18/2018