Is it possible to NOT store the folder structure when creating a zip with the package class?

87 Views Asked by At

I'm using the Package class to create a zip file. This works quite fine. The only thing I don't want to have there (which exists) is: The folder structure is also saved. Despite looking through the class I found no parameter there so I fear it is not possible, but maybe I'm overlooking something.

My question thus is: Is there any way to NOT save the folder structure into the .zip file?

Example: c:\test\mytest\blahblup.txt should be stored as blahblup.txt instead of c:\test\mytest\blahblup.txt inside the .zip file.

Code used:

        using (MemoryStream zipStream = new MemoryStream())
        {
            using (Package zipPackage = Package.Open(zipStream, FileMode.Create))
            {
                foreach (string fileName in FilesInFolderArray)
                {
                    string relativerfileName = regexLaufwerk.Replace(fileName, string.Empty).Replace(@"\", @"/");
                    PackagePart zipPartPackage = zipPackage.CreatePart(new Uri(relativerfileName, UriKind.Relative), "", CompressionOption.Maximum);

                    using (FileStream originalFileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        originalFileStream.CopyTo(zipPartPackage.GetStream());
                    }
                }
            }
0

There are 0 best solutions below