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

  • After iOS 7.1 update: red '1' badge on settings app

    Dear Apple Support Communities! The download & update to iOS 7.1 was successful. Well more or less. My iPhone 5s made no problems, everything works fine. Except the iPad Air (WiFi, 32GB). After the update to iOS 7.1 the red '1' badge on the settings

  • Palm Pre 2 Unlocked NA Bug

    Hello, I would like to let everyone know that there is a bug with the unlock screen on the palm pre 2. There are a number of people who have this problem and I am one of them. I have ordered two phones already and they have this problem. The Problem:

  • Webservice hell -  invalid content type for SOAP: TEXT/HTML

    Hi All I'm trying to call a webservice in XI and getting the dreaded  "invalid content type for SOAP: TEXT/HTML" error. Running it in XMLSpy it works perfectly well, but not in XI. Here are some screenshots: 1) The Request sent from XMLSpy [XMLSpy Re

  • 3-d Problem.....can't figure out how to make this????

    I've attached a logo i have to recreate for a customer. How do i recreate the rings??? i've tried in 3-D in revolve but the ring is always to fat. I can't get it to make it skinnier. Any one know what i'm doing wrong or have a way to fix this????

  • Get in, if u have same problem with DR4-A

    The major problem is my dr4-a locked up my computer, see if anyone can help me This is what happened: Everytime I use "Nero CD-DVD Speed" which by Nero 6 Ultra Editon to running overburn test on CD-R Disc, my Dr4-a Won't stop, the light LED keep flas