除了在C#中提取Zip文件 [英] Exception on Extracting the Zip file in C#

查看:209
本文介绍了除了在C#中提取Zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在提取码工作,解压缩zip文件,在WinRT中使用C#

I am working on Extraction Code to Extract Zip file, Using C# in winrt.

我收到来自本地驱动器这里文件:

I am getting File from Local Drive here:

StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync("dostoyevsky-poor-folk.zip");
        Stream zipMemoryStream = await file.OpenStreamForReadAsync();
        var folder = ApplicationData.Current.LocalFolder;
        // Create zip archive to access compressed files in memory stream
        using (ZipArchive zipArchive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read))
        {
            // For each compressed file...
            foreach (ZipArchiveEntry entry in zipArchive.Entries)
            {
                if (entry.Name == "")
                {
                    // Folder
                    await CreateRecursiveFolder(folder, entry);
                }
                else
                {
                    // File
                    await ExtractFile(folder, entry);
                }
            }
        }



我提取对于文件夹位置

I am Extracting For folder here:

private async Task CreateRecursiveFolder(StorageFolder folder, ZipArchiveEntry entry)
{
    var steps = entry.FullName.Split('/').ToList();

    steps.RemoveAt(steps.Count() - 1);

    foreach (var i in steps)
    {
        await folder.CreateFolderAsync(i, CreationCollisionOption.OpenIfExists);

        folder = await folder.GetFolderAsync(i);
    }
}



我提取对于文件位置:

I am Extracting For File Here:

private async Task ExtractFile(StorageFolder folder, ZipArchiveEntry entry)
        {
        var steps = entry.FullName.Split('/').ToList();
        steps.RemoveAt(steps.Count() - 1);
        foreach (var i in steps)
        {
            folder = await folder.GetFolderAsync(i);
        }
        using (Stream fileData = entry.Open())
        {
            StorageFile outputFile = await folder.CreateFileAsync(entry.Name, CreationCollisionOption.ReplaceExisting);

            using (Stream outputFileStream = await outputFile.OpenStreamForWriteAsync())
            {
                await fileData.CopyToAsync(outputFileStream);
                await outputFileStream.FlushAsync();
            }
        }
    }

当我尝试使用此我得到这个异常:System.NullReferenceException
除外越来越线是等待outputFileStream.FlushAsync()的最后一行;

When I try to use this I get this exception: 'System.NullReferenceException' . The Exception getting line is the Last line of await outputFileStream.FlushAsync();

有些时候,我得到相同的异常,当我尝试从本地驱动器挑文件。
之前获得异常等待outputFileStream.FlushAsync()这样看。

Some times I am getting same exception when I try to pick file from Local Drive. Before Getting Exception the Debugger value of await outputFileStream.FlushAsync() looking like this.

<的调试器值IMG SRC =http://i.stack.imgur.com/3gxLq.pngALT =在这里输入的形象描述>

您可以帮我出这一点。

感谢

推荐答案

最后,这是为我工作。为什么?因为我得到空值,而因为我要去的地方解压缩文件包的提取。
我相信这是提取使用的C#Windows Store应用程序的Zip文件的完美解决方案。
谢谢

Finally, It is Worked for me. Why because I am getting Null value while extraction Because of the package where I am going to extract files. I am sure this is the perfect solution to Extract Zip file for windows store apps using c#. Thanks

这篇关于除了在C#中提取Zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆