I using .Net Framework 4.0; VS 2015; Ionic.Zip.Reduced (DotNetZip.Reduced) v1.9.1.8. When I try to add a folder to the archive get an exception with the text:
The path is too long
Sample code:
using (var zipFile = new ZipFile(zipFilePath))
{
zipFile.UseZip64WhenSaving = Zip64Option.AsNecessary;
zipFile.AlternateEncodingUsage = ZipOption.Always;
zipFile.AlternateEncoding = Encoding.UTF8;
zipFile.ParallelDeflateThreshold = -1;
var dirPath = @"C:\AAAAAAAAAAA\AAAAAA\AAAAAAAAAAAAAAA\AAAAAAAAA\AAAAAAAAAAAAA\AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\";
zipFile.AddDirectory(dirPath); <-Exception
zipFile.Save();
}
In the folder is a file named: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.zip
As a result of an error:
The path is too long
Rewritten in the file-based addition to the archive (using a relative path):
using (var zipFile = new ZipFile(zipFilePath))
{
zipFile.UseZip64WhenSaving = Zip64Option.AsNecessary;
zipFile.AlternateEncodingUsage = ZipOption.Always;
zipFile.AlternateEncoding = Encoding.UTF8;
zipFile.ParallelDeflateThreshold = -1;
var dirPath = @"C:\AAAAAAAAAAA\AAAAAA\AAAAAAAAAAAAAAA\AAAAAAAAA\AAAAAAAAAAAAA\AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\";
Directory.SetCurrentDirectory(dirPath);
var files = Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories).ToArray();
foreach (var fullFilePath in files)
{
var fileName = Path.GetFileName(fullFilePath);
var relatedPath = fullFilePath.Substring(0, fullFilePath.LastIndexOf(fileName, StringComparison.InvariantCultureIgnoreCase)).Replace(zipDir, "");
var relatedFilePath = Path.Combine(relatedPath, fileName);
zipFile.AddFile(relatedFilePath); <-Exception
}
zipFile.Save();
}
The error is the same:
The path is too long
I tried to call Path.GetDirectoryName()
method, but it also returns an error:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
I found a lot of solutions but to get to work and did not work (because of the specifics of the application to the new version Framework'a can not go).
- Use Framework 4.6.2. Set
UseLegacyPathHandling = false
option inApp.Config
orSwitch.System.IO.UseLegacyPathHandling = false; Switch.System.IO.BlockLongPaths = false
- With the mention of a Group Policy and the inclusion of the option Configuration> Administrative Templates> System> Filesystem> Enable NTFS long paths, or to enable the option via the manifest
<ws2:longPathAware>true</ws2:longPathAware>
- Use the prefix
\\?\
In the path (I understand that for the new version of Framework) - Convert path to the file in 8.3 format using GetShortPathName function .... (Error remains)
Maybe someone faced such problem. I will be glad to any advice. Thanks.