Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 本地驱动器上的UWP SharpCompress访问异常,为什么?_C#_Vb.net_Uwp_Sharpcompress - Fatal编程技术网

C# 本地驱动器上的UWP SharpCompress访问异常,为什么?

C# 本地驱动器上的UWP SharpCompress访问异常,为什么?,c#,vb.net,uwp,sharpcompress,C#,Vb.net,Uwp,Sharpcompress,我正在尝试使用SharpCompress从我的UWP应用程序读取.rar文件。它可以在网络共享上正常工作,我可以从中读取归档文件,没有问题,但我在本地系统的任何位置(包括USB驱动器)上都可以获得System.UnauthorizedAccessException。我可以通过其他方法访问文件,例如StorageFile。BroadFileSystemAccess是打开还是关闭没有区别。我在C#和Vb.net中都试过,下面是我在C#中的测试应用程序代码。异常发生在ArchiveFactory.Op

我正在尝试使用SharpCompress从我的UWP应用程序读取.rar文件。它可以在网络共享上正常工作,我可以从中读取归档文件,没有问题,但我在本地系统的任何位置(包括USB驱动器)上都可以获得System.UnauthorizedAccessException。我可以通过其他方法访问文件,例如StorageFile。BroadFileSystemAccess是打开还是关闭没有区别。我在C#和Vb.net中都试过,下面是我在C#中的测试应用程序代码。异常发生在ArchiveFactory.Open

我也可以使用.net压缩方法读取Zip文件,没有问题,但它们不能读取rar文件,因此需要SharpCompress

using System;
using System.IO;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using SharpCompress;
using Windows.Storage.Pickers;
using Windows.Storage;
using SharpCompress.Archives;

namespace TestRAR
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            OpenRAR.Click += OpenRAR_Clicked;
        }

        public async void OpenRAR_Clicked(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".rar");
            picker.FileTypeFilter.Add(".cbr");
            picker.FileTypeFilter.Add(".cbz");
            picker.FileTypeFilter.Add(".zip");
            StorageFile pickfile = await picker.PickSingleFileAsync();
            if (pickfile == null) { return; }

            string pth = pickfile.Path;
            FileInfo pickInfo = new FileInfo(pth);

            try
            {
                ListRARs.Items.Clear();
                using (var Arch = ArchiveFactory.Open(pickInfo))
                {
                   foreach (IArchiveEntry a in Arch.Entries) 
                    {
                        string thisKey = a.Key;
                        ListRARs.Items.Add(thisKey);
                    }
                }
            }
            catch{ }

        }

    }
}


这是我第一次使用SharpCompress,我完全被难住了。任何人有什么想法吗?

详细解释了。@HansPassant,这并没有回答我的问题。请再读一遍。@IanBland也许你应该指定你的问题,而不是问这么宽泛的问题?我不明白为什么SharpCompress会在没有其他文件访问方式的情况下抛出未经授权的访问异常,而且只针对本地文件。您希望我指定什么?@IanBland如果您可以通过StorageFile打开一个RAR文件,那么也许您可以使用该文件将其作为流()打开,然后看起来将使用SharpCompress方法来处理该流。