0

I am creating a windows forms application which will parse the compressed files. I am getting an exception

System.IO.PathTooLongException upon debugging the files that were being parsed and extracted have their fully qualified name over 259 characters. One of the posts here mentioned about Zeta Long Paths.

I have downloaded it via Nuget package and using it in my project.

ZlpIOHelper can be used to perform file handling function.

I went through the reference via object explorer and couldn't determine how to create a FileSteam using Zeta Long Paths.

FileStream fs = File.OpenRead(archiveFilenameIn);

Stream inStream = File.OpenRead(gzArchiveName);
Stream gzipStream = new GZipInputStream(inStream);

How can the above functions be implemented using Zeta Long Paths? Or any other packages?

Not a duplicate question. .NET Version is 4.0 and long path package specific.

Nate
  • 30,286
  • 23
  • 113
  • 184
Tango
  • 386
  • 1
  • 6
  • 29
  • 1
    Possible duplicate of [How to avoid System.IO.PathTooLongException?](https://stackoverflow.com/questions/530109/how-to-avoid-system-io-pathtoolongexception) – demo Aug 28 '17 at 13:01
  • 1
    @demo not a duplicate. The solution mentioned in that post is not applicable here as .NET Version is 4.0. Also, the question is how could the Stream be implemented using Zeta Long Paths. – Tango Aug 28 '17 at 13:04
  • If you compile on .NET 4.6.2, the path too long limit can be removed. see here: https://stackoverflow.com/a/38889598/711061 – Mauro Sampietro Aug 28 '17 at 13:25
  • @sam tried on .NET 4.6.2 and the mentioned method is Windows 10 dependent. Unfortunately, restricted to .NET 4.0. – Tango Aug 28 '17 at 13:43
  • @Tango not sure if still relevant for you, but see my proposed answer – Guillaume ZAHRA Feb 01 '19 at 17:31

1 Answers1

1

Creating a FileStream through Zeta Long Path is not automatic, but possible.

You must first get/create an SafeFileHandle to your file. I don't have yet tested on a read scenario, but here an exemple of how to write some Stream data to your own FileStream on a deeply nested path:

using (var fileHandle = ZlpIOHelper.CreateFileHandle(very_long_outputPath, ZetaLongPaths.Native.CreationDisposition.CreateAlways, ZetaLongPaths.Native.FileAccess.GenericAll, ZetaLongPaths.Native.FileShare.Read))
{
    using (FileStream streamWriter = new System.IO.FileStream(fileHandle, System.IO.FileAccess.Write))
    {
       //Your code logic here
    }
}
Guillaume ZAHRA
  • 321
  • 4
  • 9