简体   繁体   English

压缩或压缩文件-Windows Phone通用应用程序-C#

[英]Compress or Zip a File - Windows Phone Universal Apps - C#

I need to compress file for send in HttpWebRequest for a server. 我需要压缩文件以便在服务器的HttpWebRequest中发送。 I try to use external classes of C# but doesn't work in Universal Apps. 我尝试使用C#的外部类,但在Universal Apps中不起作用。 I try this with a original classes that can I use in Universal apps and this is my code: 我尝试使用可以在Universal应用程序中使用的原始类,这是我的代码:

 //SycroZipFile and UploadFile are StorageFile type.
 using (Stream writeStream = await SyncroZipFile.OpenStreamForWriteAsync())
 {
     using (Stream readStream = await UploadFile.OpenStreamForReadAsync())
     {
         await readStream.CopyToAsync(writeStream);
     }
 }

But the ZipFile is corrupt and doesn't work, any one can help me for compress file in Windows Phone Universal Apps? 但是ZipFile损坏并且无法正常工作,有人可以帮助我在Windows Phone Universal Apps中压缩文件吗? Thanks a lot, sorry for my english and Thanks in advance! 非常感谢,对不起我的英语,在此先感谢!

Finally I could solve my problem! 终于我可以解决我的问题了! If you are programmer of Windows Phone Universal Apps have a problems with a external classes to zip a files, you can use my code with original classes from Visual that can use in Universal Apps: 如果您是Windows Phone Universal Apps的程序员,则在使用外部类来压缩文件时遇到问题,则可以将我的代码与Visual的原始类(可以在Universal Apps中使用)一起使用:

//The UploadFile and SyncroZipFile are StorageFile's.
using (Stream StreamToUploadFile = await UploadFile.OpenStreamForWriteAsync())
{
    using (Stream StreamToSyncroZipFile = await SyncroZipFile.OpenStreamForWriteAsync())
    {
        using (ZipArchive UploadFileCompressed = new ZipArchive(StreamToSyncroZipFile, ZipArchiveMode.Update))
        {
            ZipArchiveEntry NewZipEntry = UploadFileCompressed.CreateEntry(UploadFileName);

            using (Stream SWriter = NewZipEntry.Open())
            {
                 await StreamToUploadFile.CopyToAsync(SWriter);
            }
        }
    }
}

This code work perfectly for my, and finally my ZipArchive it's not corrupt and I can open it! 这段代码非常适合我,最后我的ZipArchive它没有损坏,可以打开它! Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在C#Windows Universal Apps中将字符串附加到文本文件中 - How to append a string into a text file in C# Windows Universal Apps 在Windows通用应用程序C中流式传输图像 - streaming images in windows universal apps c# FileSavePicker for Audio文件在Windows Phone 8.1 Universal Apps中不起作用 - FileSavePicker for Audio file is not working in Windows Phone 8.1 Universal Apps 如何在C#中对Windows Phone应用程序进行逻辑删除 - How to tombstone windows phone apps in c# 使用C#在通用Windows应用程序中未检测到键盘布局更改 - Keyboard layout change not detected in universal windows apps with C# 通用Windows平台(UWP)应用程序的C#服务器/客户端应用程序 - C# Server / Client Application for Universal Windows Platform (UWP) apps Windows Phone 8通用应用程序-在C#代码中使用JS - Windows Phone 8 Universal App - Use JS within C# Code ComboBox Universal Apps Windows Phone的SelectedValue - SelectedValue of a ComboBox Universal Apps Windows Phone 如何在Windows应用商店8.1应用中创建带密码的zip文件c# - How can i create a zip file with a password in windows store 8.1 apps c# combobox Universal Apps Windows Phone中的条件 - Conditions in combobox Universal Apps Windows Phone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM