Reputation: 9546
I'm trying to decompress a zip file:
public string unzip(string zipFilePath, string destinationFolder)
{
try
{
ZipFile.ExtractToDirectory(zipFilePath, destinationFolder);
return destinationFolder;
}
catch (Exception ex)
{
throw ex;
}
}
When I pass in the following value for zipFilePath
:
t:\aaaaaaa aaaaaaaaaa aaaaaaaa\aaaa aaaaaa\aaaa aaaaaaaaaa aaaaaa\aaaa aaaaaa aaa.a aaaa\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.zip
and this destinationFolder
:
C:\Users\A312\Documents\Visual Studio 2013\Projects\PDFConverterTester\PDFConverterTester_BatchGUI\bin\Debug\tempZip\466-qqqqqqqqq qqqqqqqq qqqqqq qqqq qqqqq qqqqqqqqqqq
this exception is thrown:
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.
When I decompress it to destinationFolder
using PKZip, there is no problem.
But there is a file in the zip archive that, when unzipped, has a full path of 261 characters.
Any idea how to deal with this?
Update: My company's IT policy will not allow me to install any new software, so I'm trying to figure out how to resolve this with Windows API calls from my existing .NET 4.5 installation of Visual Studio.
Upvotes: 3
Views: 2901
Reputation: 9546
I ended up using 7zip instead, as per this answer, because it doesn't have a character limitation.
Upvotes: 0
Reputation: 26033
Try prepending the \\?\
prefix to your full path in order to circumvent the 260/248 character limitation:
\\?\t:\aaaaaaa aaaaaaaaaa aaaaaaaa\aaaa aaaaaa\aaaa aaaaaaaaaa aaaaaa\aaaa aaaaaa aaa.a aaaa\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.zip
More information can be found here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
You should also use this function sparingly as it disables Windows' check for valid filenames in the file system.
Upvotes: 3