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" />
paket add Chessar.LongPaths --version 1.1.8
#r "nuget: Chessar.LongPaths, 1.1.8"
// Install Chessar.LongPaths as a Cake Addin #addin nuget:?package=Chessar.LongPaths&version=1.1.8 // Install Chessar.LongPaths as a Cake Tool #tool nuget:?package=Chessar.LongPaths&version=1.1.8
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:
- .NET Framework 4.6.2+ (see .NET Blog)
How to use
- Add the Chessar.LongPaths NuGet package to the project.
- In the file
app.config
(orweb.config
), in the sectionruntime
, add:
<configuration>
...
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
...
- In the code (when you start the application or at the beginning of
Main
) add code:
...
using static Chessar.Hooks;
...
PatchLongPaths();
- Usage
...
var fileInfo = new FileInfo(path);
var fullName = fileInfo.FullName; // with long path prefix
...
- 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:
- For the following methods:
DirectoryInfo.MoveTo(String)
Image.Save(String[, ...])
hook is not used, so when using them, add the long path prefix:
...
using static Chessar.Hooks;
...
var di = new DirectoryInfo(...);
di.MoveTo(path.AddLongPathPrefixAndFixSeparators());
TODO
- Add long path support in methods from
Notes
. - Make hooks more thread safe.
License
MIT - See LICENSE
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:
- .NET Framework 4.6.2+ (see .NET Blog)
How to use
- Add the Chessar.LongPaths NuGet package to the project.
- In the file
app.config
(orweb.config
), in the sectionruntime
, add:
<configuration>
...
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
...
- In the code (when you start the application or at the beginning of
Main
) add code:
...
using static Chessar.Hooks;
...
PatchLongPaths();
- Usage
...
var fileInfo = new FileInfo(path);
var fullName = fileInfo.FullName; // with long path prefix
...
- 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:
- For the following methods:
DirectoryInfo.MoveTo(String)
Image.Save(String[, ...])
hook is not used, so when using them, add the long path prefix:
...
using static Chessar.Hooks;
...
var di = new DirectoryInfo(...);
di.MoveTo(path.AddLongPathPrefixAndFixSeparators());
TODO
- Add long path support in methods from
Notes
. - Make hooks more thread safe.
License
MIT - See LICENSE
Release Notes
Fixed enumerating of FS items for a drive letter
Dependencies
-
.NETFramework 4.6.2
- No dependencies.
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated |
---|---|---|
1.1.8 | 480 | 10/25/2018 |
1.1.7 | 409 | 10/2/2018 |
1.1.7-rc003 | 355 | 10/2/2018 |
1.1.6 | 388 | 9/24/2018 |
1.1.5 | 371 | 9/23/2018 |
1.1.4 | 401 | 9/21/2018 |
1.1.3 | 381 | 9/20/2018 |
1.1.2 | 395 | 9/16/2018 |
1.1.1 | 387 | 9/12/2018 |
1.1.0 | 390 | 9/10/2018 |
1.0.9 | 431 | 9/4/2018 |
1.0.8 | 422 | 8/26/2018 |
1.0.7 | 440 | 7/30/2018 |
1.0.6 | 423 | 7/25/2018 |
1.0.5 | 423 | 7/19/2018 |
1.0.4 | 469 | 7/18/2018 |
1.0.3 | 476 | 7/18/2018 |
1.0.2 | 478 | 7/18/2018 |
1.0.1 | 487 | 7/12/2018 |
1.0.0 | 486 | 7/12/2018 |
1.0.0-rc005 | 403 | 7/5/2018 |
1.0.0-rc004 | 469 | 6/20/2018 |
1.0.0-rc003 | 466 | 6/18/2018 |