0
var appFolder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("Test");

Update: Got it - Used Above Line.------

var folder = KnownFolders.DocumentsLibrary;
StorageFolder subFolder = await folder.GetFolderAsync("Test");
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".txt");
QueryOptions queryOptions = new QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByName, fileTypeFilter);
StorageFileQueryResult queryResult = subFolder.CreateFileQueryWithOptions(queryOptions);
var files = await queryResult.GetFilesAsync();

foreach (var file in files)
{
   string name = file.Name;
   Debug.WriteLine(name);
}

Learning to build for UWP. Here is the code to get all the text files from a folder in the Documents folder. But I want to create the Test folder if it doesn't exist in the documents folder.

Ajay G
  • 45
  • 7
  • Does this answer your question? [If a folder does not exist, create it](https://stackoverflow.com/questions/9065598/if-a-folder-does-not-exist-create-it) – User2585 Jan 30 '20 at 15:07
  • That answer isn't for UWP. – Ajay G Jan 30 '20 at 15:11
  • You can still use the same code, it's a C#/ .net question not specific for UWP – User2585 Jan 30 '20 at 15:19
  • Getting Error : System.UnauthorizedAccessException: 'Access to the path 'C:\Users\....\bin\x86\Debug\AppX\Typing' is denied.' – Ajay G Jan 30 '20 at 15:41
  • @User2585 UWP has a different security model from Desktop. – Raymond Chen Jan 30 '20 at 17:49
  • Note that your question doesn't match your title. Your title asks about checking if a folder exists, but your question is about creating a folder if it doesn't already exist. The way to check if something exists is to call `TryGetItemAsync` and see if it returns something. If you want to create a folder if it doesn't already exist then use `CreateFolderAsync` with a collision option of `OpenIfExists` to say "If it already exists, then just give me the existing item." – Raymond Chen Jan 30 '20 at 17:50

1 Answers1

0
if(!System.IO.Directory.Exists(System.IO.Path.Combine(folder,"Test")))
{
    System.IO.Directory.Create(System.IO.Path.Combine(folder,"Test")));
} 

Might have the syntax slighly out as not doing it on a computer, but I think that should do it.

Bigtoe
  • 3,177
  • 1
  • 29
  • 44