/// <summary> /// Sets the private varable Sfolder to the current directory /// Example: If StartingDirectory = folder1\\folder2 /// Directories under folder2 are found /// </summary> private void SetDirectory(string StartingDirectory) { try { char slash = '\\'; Sfolder = SDevice; if (StartingDirectory.IndexOf(slash) == -1) { if (StartingDirectory != "Root") { Sfolder = Sfolder.CreateFolder(StartingDirectory, CreationCollisionOption.ReplaceExisting); Debug.WriteLine("Successfully created folder: " + Sfolder.Path); } } else { string[] str = StartingDirectory.Split(slash); for (int i = 0; i < str.Length; i++) { Sfolder = Sfolder.CreateFolder(str[i], CreationCollisionOption.ReplaceExisting); Debug.WriteLine("Successfully created folder: " + Sfolder.Path); } } } catch (Exception) { Debug.WriteLine("Directories are not supported for internal storage"); } }
/// <summary> /// Sets the private varable Sfolder to the current directory /// Sets the private varable Fname to the curent file name /// </summary> /// <param name="FilePath"></param> private void SetDirectoryandFilename(string FilePath) { try { char slash = '\\'; Sfolder = SDevice; if (FilePath.IndexOf(slash) == -1) { Debug.WriteLine("File path -> " + FilePath); Fname = FilePath; } else { string[] str = FilePath.Split(slash); for (int i = 0; i < str.Length - 1; i++) { Sfolder = Sfolder.CreateFolder(str[i], CreationCollisionOption.ReplaceExisting); Debug.WriteLine("Successfully created folder: " + Sfolder.Path); } Fname = str[str.Length - 1]; Debug.WriteLine("File name -> " + Fname); } } catch (Exception) { Debug.WriteLine("Directories are not supported for internal storage"); } }
public static void Execute(StorageFolder device) { Console.WriteLine($"== Scenario1_CreateAFolderInStorage =="); try { // create a folder (failing if there is already one with this name) var folderNew = device.CreateFolder("folder1", CreationCollisionOption.FailIfExists); Console.WriteLine($"OK: Successfully created folder: {folderNew.Path}"); } catch (Exception) { Console.WriteLine($"ERROR: can't create the folder as it already exists."); } }
/// <summary> /// Helper method to create a Folder at a specific location /// </summary> /// <param name="location">Location to create folder</param> /// <param name="folderName">Folder name to create</param> /// <returns></returns> static StorageFolder CreateFolderHelper(StorageFolder location, String folderName, CreationCollisionOption option) { StorageFolder folderNew = null; try { // create a folder (failing if there is already one with this name) folderNew = location.CreateFolder(folderName, option); Console.WriteLine($"OK: Successfully created folder: {folderNew.Path}"); } catch (Exception) { Console.WriteLine($"ERROR: Can't create the folder as it already exists."); } return(folderNew); }