c# - Launching a FilePicker or FolderPicker from a UICommand / MessageDialog -


when windows store app starts want prompt user choose local storage folder using folderpicker , saving futureaccesslist. prompt use messagedialog.

protected async override void onnavigatedto(navigationeventargs e) {     base.onnavigatedto(e);      var messagedialog = new messagedialog("please pick folder you'd store documents", "choose storage");     messagedialog.commands.clear();     messagedialog.commands.add(new uicommand("ok", async (command) =>     {         await pickfolder();     });     await messagedialog.showasync(); }  private async task pickfolder() {     folderpicker folderpicker = new folderpicker();     folderpicker.suggestedstartlocation = pickerlocationid.desktop;     folderpicker.filetypefilter.add(".txt");     folder = await folderpicker.picksinglefolderasync();     // lets ignore cancellations     storageapplicationpermissions.futureaccesslist.addorreplace("myfolder", folder); } 

this code doesn't work - access denied error

access denied. (exception hresult: 0x80070005 (e_accessdenied)) 

i thought using messagedialog.showasync() enough around doesn't seem work. ideas?

do have abandon pretty winrt messagedialogs in favor of home grown?

the messagedialog's command fires before closes, , can't open second modal dialog while first still up.

you need delay call pickfolder until after messagedialog has completed. since you're awaiting anyway can call after showasync. it's moot here since ok option, can switch on command chosen pick between multiple options.

protected async override void onnavigatedto(navigationeventargs e) {     base.onnavigatedto(e);      var messagedialog = new messagedialog("please pick folder you'd store documents", "choose storage");     messagedialog.commands.clear();     uicommand okcommand = new uicommand("ok");     messagedialog.commands.add(okcommand);     var cmd = await messagedialog.showasync();     if (cmd == okcommand)     {         await pickfolder();     } } 

another option add delay (e.g. calling pickfolder in dispatcher.runasync block) within uicommand handler before calling pickfolder messagedialog can close.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -