uwp - How to add folder to StorageLibrary without RequestAddFolderAsync in C# -


i need save app files plugged sd card. i'm using uwp , windows 10.
msdn tells how to it windows libraries.

var mypicslibrary = await windows.storage.storagelibrary.getlibraryasync(windows.storage.knownlibraryid.pictures); await mypicslibrary.requestaddfolderasync(); 

requestaddfolderasync() shows file picker, user can choose folder add pictures. in case it's folder, created on sd card.

is there way thing without file picker dialog?

i'm trying like this:

var mypicslibrary = await windows.storage.storagelibrary.getlibraryasync(windows.storage.knownlibraryid.pictures);  // logical root folder external storage devices. storagefolder externaldevices = windows.storage.knownfolders.removabledevices;  // first child folder, represents sd card. storagefolder sdcard = (await externaldevices.getfoldersasync()).firstordefault();  var folder = await sdcard.createfolderasync("mysdcardfolder");  mypicslibrary.folders.insert(mydocs.folders.count+1, folder); // notimplementedexception: 'the method or operation not implemented.' mypicslibrary.folders.add(folder); // notimplementedexception: 'the method or operation not implemented.' 

or maybe can same without using windows libraries directly working sdcard?

thanks lot!

edit:

in hand question sounds "how save files plugged sd card?"

the storagelibrary.folders gets folders in current library, return iobservablevector of storagefolder. when add folder iobservablevector, not change folder in files system. throw "the method or operation not implemented." exception.

we should able name of folder, , create folder uses name. can storagefile.copyasync method copy file in folder.

for example:

public static async task copyfolderasync(storagefolder source, storagefolder destinationcontainer, string desiredname = null) {     storagefolder destinationfolder = null;     destinationfolder = await destinationcontainer.createfolderasync(         desiredname ?? source.name, creationcollisionoption.replaceexisting);      foreach (var file in await source.getfilesasync())     {         await file.copyasync(destinationfolder, file.name, namecollisionoption.replaceexisting);     }     foreach (var folder in await source.getfoldersasync())     {         await copyfolderasync(folder, destinationfolder);     } } 

then can use copyfolderasync method copy folder in picture library.

var mypicslibrary = await windows.storage.storagelibrary.getlibraryasync(windows.storage.knownlibraryid.pictures); var myfolder = mypicslibrary.folders[0]; storagefolder externaldevices = windows.storage.knownfolders.removabledevices; storagefolder sdcard = (await externaldevices.getfoldersasync()).firstordefault(); var folder = await sdcard.createfolderasync("mysdcardfolder"); await copyfolderasync(folder, myfolder); 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -