1
votes

hi i have a simple question how i can find the path of a file which had been already saved in the isolated storage

using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(App.filePath, FileMode.Create, store))
            {

                byte[] buffer = new byte[1024];
                while (e.Result.Read(buffer, 0, buffer.Length) > 0)
                {
                    stream.Write(buffer, 0, buffer.Length);
                }
                stream.Close();

            }

now i would read this file i need this path to use it as a parameter of method

Epub epub =new Epub([file path]) 

any help will be greatly appreciated

3

3 Answers

0
votes

If a file is in IsolatedStorage you either put there yourself or it's the one created by the system to store settings.

If you put it there you must have had the path at some point previously. You just need to track the file names (and paths) you're using.

You should not try and access the settings file directly.

0
votes

Try this

using (var AppStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] filenames=AppStorage.getFileNames();
//choose the filename you want or
//enumerate directories and read file names in each directory
string[] directories=AppStorage.getDirectories();
}

For each directory you have to add the filepath upto that directory just like in any windows file browsing.

Hope it helps.Post your further queries.

0
votes

There is no need for you to get the path to the file if you are the one who put the file in the isolated storage. The entire guide to how properly read and write files to the app isostore is available here, and this should be your starting point.

The entire reading routine is limited to this:

using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read))
{
    using (StreamReader reader = new StreamReader(fileStream))
    {
       Console.WriteLine("Reading contents:");
       Console.WriteLine(reader.ReadToEnd());
    }
}

Where myIsolatedStorage is equal to IsolatedStorageFile.GetUserStoreForApplication() (akak your local app storage box).

No need for Reflection, as you showed in the comments. The can be relative to a folder, when you're attempting to read, so something like /MyFolder/myFile.txt will work as well, given that the folder exists.

Your problem is this - pushing the relative path in the isostore to the Epub class, which probably does not read directly from the isostore and uses a full path instead. The nature of the Windows Phone OS is such that it won't let a third-party application without proper permissions to access content directly through a full path reference. So you need to figure out a way to pass binary content to the class instead of a path.