How to extract String path from ApplicationData.Current.LocalFolder

306 Views Asked by At

I need to create a ListBox with saved files in ApplicationData.Current.LocalFolder, that I can later use to open these files.

I have something like this:

string path = ApplicationData.Current.LocalFolder;

DirectoryInfo dinfo = new DirectoryInfo(@path);    
FileInfo[] Files = dinfo.GetFiles("*.txt");

foreach (FileInfo file in Files)
{
listbox1.Items.Add(file.Name);
}

But even though I found some sample code that just assigns ApplicationData.Current.LocalFolder directly to string, I get an error: "Cannot implicitly convert "Windows.Storage.StorageFoler" to string."

Can you tell me how to do it?

Thanks

1

There are 1 best solutions below

1
Ryszard On

Ok,

I have solved it myself, so for anyone looking for an answer, here you go:

string path = ApplicationData.Current.LocalFolder.Path;

DirectoryInfo dinfo = new DirectoryInfo(@path);    
FileInfo[] Files = dinfo.GetFiles("*");

foreach (FileInfo file in Files)
{
     historia.Items.Add(file.Name);
}