SoFunction
Updated on 2025-03-06

C# Example of Implementing Metro File Compression and Decompression

Add a new picture to

Copy the codeThe code is as follows:

StorageFile jpg = await ("");
            StorageFile zip = await ("");

//Change the above sentence into the following and it becomes a compressed file
            //StorageFile zip = await (+".zip",);


            using (ZipArchive archive = new ZipArchive((await ()).AsStream(), ))
            {
                ZipArchiveEntry readmeEntry = ();
                byte[] buffer = (await (jpg));
                using (var writer = ())
                {
                    await (buffer, 0, );
                }
            }

Delete it from

Copy the codeThe code is as follows:

StorageFile zip = await ("");
            using (ZipArchive archive = new ZipArchive((await ()).AsStream(), ))
            {
//Delete the file
                ("").Delete();
            }

Export, newFile is the file to be exported

Copy the codeThe code is as follows:

StorageFile zip = await ("");
            using (ZipArchive archive = new ZipArchive((await ()).AsStream(), ))
            {
ZipArchiveEntry zipArchiveEntry = ("").
using (Stream fileData = ())
                            {
                                StorageFile newFile = await (, );
                                using (IRandomAccessStream newFileStream = await ())
                                {
                                    using (Stream s = ())
                                    {
                                        await (s);
                                        await ();
                                    }
                                }
                            }
}