i have this c# code and i want to delete a certain sub directory in Documents Library. However this produces an error because the directory is not empty. I hope someone can guide me on how to do this.
thank you for any prompt reply.
StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
var queryResult = storageFolder.CreateFolderQuery();
IReadOnlyList<StorageFolder> folderList = await queryResult.GetFoldersAsync();
foreach (StorageFolder folder in folderList)
{
await folder.DeleteAsync();
}
You could use the
StorageFolder.GetFilesAsync()to obtain a list of all the files present in the folders and delete them prior to deleting the folders since there is no way in theDeleteAsync()method to specify subfolders and files.More info: StorageFolder class | MSDN