UWP SharpCompress Access Exception On Local Drives, Why?

149 views Asked by At

I'm trying to use SharpCompress to read .rar files from my UWP application. It works fine on network shares from which I can read the archive no problem, but I get System.UnauthorizedAccessException on files anywhere on the local system including for instance USB drives. I have access to the files by other methods e.g. StorageFile. It makes no difference whether BroadFileSystemAccess is on or off. I've tried in both C# and Vb.net Here's the code of my test app in C#. The exception occurs at ArchiveFactory.Open.

I can also read Zip files no problem using the .net Compression methods but they can't do rar files, hence needing 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{ }

        }

    }
}

This is the first time I've used SharpCompress and I'm completely stumped. Any ideas anyone?

0

There are 0 answers