c# - How to create a path using the Windows.Storage API? -


system.io.createdirectory() not available on .net windows store apps.

how can implement equivalent method? storagefolder.createfolderasync() creates subfolder inside current folder, in case have path , need create folders doesn't exist in path.

the path inside app's sandbox in windows.

there's no api same behaviour of system.io.createdirectory(), implemented using windows.storage classes:

    // , directories specified in path created, unless exist or unless      // part of path invalid. if directory exists, method not create      // new directory.     // path parameter specifies directory path, not file path, , must in      // applicationdata domain.     // trailing spaces removed end of path parameter before creating directory.     public static void createdirectory(string path)     {          path = path.replace('/', '\\').trimend('\\');         storagefolder folder = null;          foreach(var f in new storagefolder[] {             applicationdata.current.localfolder,              applicationdata.current.roamingfolder,              applicationdata.current.temporaryfolder } )         {             string p = parsepath(path, f);             if (f != null)             {                 path = p;                 folder = f;                 break;             }         }          if(path == null)             throw new notsupportedexception("this method implementation doesn't support " +             "parameters outside paths accessible applicationdata.");          string[] foldernames = path.split('\\');         (int = 0; < foldernames.length; i++)         {             var task = folder.createfolderasync(foldernames[i], creationcollisionoption.openifexists).astask();             task.wait();             if (task.exception != null)                 throw task.exception;             folder = task.result;         }     }      private static string parsepath(string path, storagefolder folder)     {         if (path.contains(folder.path))             {                 path = path.substring(path.lastindexof(folder.path) + folder.path.length + 1);                 return path;             }         return null;     } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -