I'm trying to make a universal app which merely opens a folder (like a shortcut) but allows for the new start tile design with custom color and bigger icon.
When I open the FolderPicker
to give the application access to the directory, I get an error, and I have no idea why.
System.Runtime.InteropServices.COMException
Please assist.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.AccessCache;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
doPickFile();
//Application.Current.Exit();
}
private async void doPickFile()
{
bool folderAdded = StorageApplicationPermissions.FutureAccessList.ContainsItem("\\\\server\\share$");
if (!folderAdded)
{
var openPicker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.PicturesLibrary };
StorageFolder folder = await openPicker.PickSingleFolderAsync();
if (folder.Path == "\\\\server\\share$")
{
StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
}
}
else
{
StorageFolder pickedFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("\\\\server\\share$");
await Windows.System.Launcher.LaunchFolderAsync(pickedFolder);
}
}
}
}
Specifically the debugger stops at the line:
StorageFolder folder = await openPicker.PickSingleFolderAsync();