[英]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.