Cant get list of files from a folder (even though the folder and files are created with the same app)

Ok so each character rolled with my app gets saved as an html file in a folder i create on the sdcard called RpgApp
the code to do this is 
private async Task saveToHtmlCharacter(string name)
StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
StorageFolder sdcard = (await externalDevices.GetFoldersAsync()).FirstOrDefault(); //Windows.Storage.ApplicationData.Current.LocalFolder;
var dataFolder = await sdcard.CreateFolderAsync("RpgApp",
CreationCollisionOption.OpenIfExists);
var file = await dataFolder.CreateFileAsync(name+".html",
CreationCollisionOption.ReplaceExisting);
using (StreamWriter writer = new StreamWriter(await file.OpenStreamForWriteAsync()))
writer.WriteLine("<html><head><title>Character File for " + z.charNameFirst + " " + z.charNameSecond + "</title></head><body>");
//trimed for the post
now this as i say works perfectly and i can confirm that the files show up in the "RpgApp"folder
now the next step is to have the app read the names of each of those html files and create a seperate button for each one named for the filename and with the filename as content (later i will link them up to load the html file they are named for in a webbrowser
panal)
here is the code that *should* do that
private async Task readFiles()
z.test.Clear();
StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
StorageFolder folder = (await externalDevices.GetFolderAsync("RpgApp"));
IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync();
//z.test.Add("dummy");
foreach (StorageFile file in fileList)
z.test.Add(file.Name);
public async void buttonTest()
await readFiles();
CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
foreach (string name in z.test)
Button button1 = new Button();
button1.Height = 75;
button1.Content = name;
button1.Name = name;
testStackPanal.Children.Add(button1);
now i say should as what i get is an error of "A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll" (2 of them in fact one after another)
more detailed error is at http://pastebin.com/3hBaZLQ9
now i went through checking line after line to find the error and line that causes it is:
StorageFolder folder = (await externalDevices.GetFolderAsync("RpgApp"));
in the readFiles method
i checked to make sure the case is right etc and its spot on, that IS the folder name, and remember my app creates that folder and creates the files that are inside that folder (and only files my app creates are in that folder) so it should have access
im 100% stuck its taken me all day to get the files to save and now i cant get them to list correctly
I have tested the button creation function with fake list data and that worked fine, as i say the error is when i tell it to look at the folder it created
all help most greatfully recieved

this was actually solved for me on another forum thread 
async Task<bool> continueToReadAllFiles(StorageFolder folder)
if (folder == null)
return false;
if (folder.Name.Equals("RpgApp", StringComparison.CurrentCultureIgnoreCase))
var files = await folder.GetFilesAsync();
foreach (var file in files)
test.Add(file.Name);
return false;
var folders = await folder.GetFoldersAsync();
foreach (var child in folders)
if (!await continueToReadAllFiles(child))
return false;
return true;
public async void buttonTest()
test.Clear();
StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
var folders = await externalDevices.GetFoldersAsync();
foreach (var folder in folders)
if (!await continueToReadAllFiles(folder))
break;
//.... commented out
...now i say solved this is more a workaround...but it works.
I would love to know why we cant just scan the RpgApp folder instead of having to scan the whole dc card and disregard all thats not in the RpgApp folder

Similar Messages

Maybe you are looking for

  • SLiM crashes X on switch to console, prevents resume

    i'm facing something of a mystery, here. when i switch to a virtual console ( <ctrl>+<alt>+f{1-9} ) after logging into a desktop session via slim, the x session crashes and i'm presented with a new slim login screen. i first noticed this while (final

  • Podcast subscriptions no longer download

    Since a few days ago, my subscribed video podcasts like "Ellen in a minute" and "Meet the Press" have stopped downloading. Now matter how many times I try to "get" the missing episodes the download never starts and then times out. The store otherwise

  • I have a new computer.  How do I transfer my itunes library to the new computer?

    I have a new computer.  How do I transfer my itunes library to the new computer?

  • How to quit apps?

    hi, i've recently switched from blackberry to the iphone 4 and was curious to how i quit apps? on my blackberry i know that if i keep anything running in the background e.g. mail, browser and not formally 'close' it, it will slow down my bb. does iph

  • My tools aren't responding

    I've uploaded a photo which was 72 dpi and my tools aren't responding as fast as they normally do. AI works fine but photoshop is slow. I have paid for the monthly subscription