In my Windows Store apps, I have always used:
StorageFolder folder = await KnownFolders.DocumentsLibrary.GetFolderAsync("Folder Name");
if(folder != null)
{
// Folder exists. Open it and load any existing files.
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
// We now have the files. Do something with them.
}
else
{
// Folder does not exist. Create it.
folder.CreateFolderAsync("Folder Name", CreationCollisionOption.OpenIfExists);
}
But just now, I thought, why can't I do it this way?
StorageFolder folder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("Folder Name", CreationCollisionOption.OpenIfExists);
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
if(files != null)
{
// We now have the files. Do something with them.
}
To the best of my knowledge, the first block of code I wrote is the "standard" way - or more commonly-seen way of doing it. But since the second way also works, I am now unsure of which one to use. They both work, but is there any reason why I should not do it the second way?