lala
lala

Reputation: 151

How to retrieve files from the isolated storage

how do i allow this code to retrieve the files from a directory? For example, my directory name is "Folder Name":

private ObservableCollection<FileItem> LoadFiles()
{
    ObservableCollection<FileItem> files = new ObservableCollection<FileItem>();

    foreach (string filePath in this.Store.GetFileNames())
        files.Add(new FileItem { FileName = filePath });
    return files;
}

EDIT:

I've tried this, and it still isn't working:

 private ObservableCollection<FileItem> LoadFiles()
        {
            ObservableCollection<FileItem> files = new ObservableCollection<FileItem>();


            foreach (string filePath in this.Store.GetFileNames())
                files.Add(new FileItem { "FlashCardApp\\" + FileName = filePath });
            return files;
        }

Upvotes: 1

Views: 1243

Answers (4)

lala
lala

Reputation: 151

I've finally found the answer to my own question.

This is how it is suppose to be:

private ObservableCollection<FileItem> LoadFiles()
{
    ObservableCollection<FileItem> files = new ObservableCollection<FileItem>();

    foreach (string filePath in this.Store.GetFileNames("FlashCardApp\\"))
        files.Add(new FileItem { FileName = filePath });
    return files;
}

By having \ after the folder name, "FlashCardApp\\", it will retrieve the files from the directory.

Upvotes: 1

Claus J&#248;rgensen
Claus J&#248;rgensen

Reputation: 26345

I doubth that your folder name is correct. I'll recommend you use storeFile.GetDirectoryNames("*") to see what the correct paths for the directory is.

Microsoft wrote a great example I think you should try and take a look at, since there's nothing obvious wrong with your code.

Upvotes: 0

apophis
apophis

Reputation: 269

To retrieve file names, you can use System.IO:

string[] filePaths = Directory.GetFiles(path, "*.txt")

The Directory class is in System.IO.

Upvotes: 0

Lysgaard
Lysgaard

Reputation: 234

 DirectoryInfo di = new DirectoryInfo("c:/Folder Name");
 FileInfo[] rgFiles = di.GetFiles("*.*");
 foreach(FileInfo fi in rgFiles)
 {
 //Do something
  fi.Name        
 }

Upvotes: 0

Related Questions