×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Nokia Developer Expert
    Join Date
    Aug 2008
    Posts
    43

    Windows Phone and Access to Filesystem

    Hi,
    I'm developing an application and I'd like to know, if there is any way to access filesystem (R/W)?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Windows Phone and Access to Filesystem

    It depends on what file system you want to access
    Quote Originally Posted by http://msdn.microsoft.com/en-us/library/ff402541(v=VS.92).aspx
    For a Windows Phone application, all I/O operations are restricted to isolated storage and do not have direct access to the underlying operating system file system or to the isolated storage of other applications.
    (if you open the link, API-s for this isolated storage stuff are described nearby)

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    1

    Re: Windows Phone and Access to Filesystem

    Isolated storage is a filesystem that only your app can see, it can't access other parts of the phone.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Location
    India, Nashik
    Posts
    816

    Re: Windows Phone and Access to Filesystem

    If you are from j2me background then something similar to recordstore , there is no api as such so far to access files

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    19

    Re: Windows Phone and Access to Filesystem


  6. #6
    Regular Contributor
    Join Date
    Jan 2009
    Location
    India
    Posts
    138

    Re: Windows Phone and Access to Filesystem

    Hi Mimuurin,

    There is no direct access to the operating system's file system.To access the file system in Windows Phone 7, you can use the Isolated Storage. it is a Virtual File System. Isolated storage allows you to store data locally. There are two ways to use isolated storage.
    - The first way is to save or retrieve data as key/value pairs by using the IsolatedStorageSettings class.
    - The second way is to save or retrieve files by using the IsolatedStorageFile class.

    This improves security and reduces chances of unauthorized access and data corruption.

    Hope it helps.
    Last edited by pavan.pareta; 2011-07-19 at 08:28. Reason: Added MSDN Link
    Pavan Pareta
    Sr. Software Engineer
    http://windows-mobile-dev.blogspot.com

  7. #7
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Windows Phone and Access to Filesystem

    Hi All,

    I have read through the posts, but was unable to get solution to my problem, very much related to File access.

    I have a file, which I want to use in the application. NOTE: This file is already there with me, and i want to use to deploy it. How to put it in IsolatedStorageFile storage or how to embed it into my application, so that it is available for reading.

    The files which I want mainly contains some settings information, some localization strings, and some text to display on the screen. So I want these 2 files to be available to me during execution, what is the way ?

    To summarize the question:
    From the example codes of IsolatedStorageFile - what I could understand is that you can write and then later read the files which are private to you, but how to embed a file along with the application?
    Amit Kankani
    Nokia Developer Champion

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Windows Phone and Access to Filesystem

    As I understand you can not deploy files to the isolated storage. A thing you can certainly do is deploying them with the .xap, and save them into the isolated storage when you need to modify them.
    On the implementation side it affects the loader routine, you try to load data from the file first, and if the file does not exist, you turn to the resource.

  9. #9
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Windows Phone and Access to Filesystem

    Quote Originally Posted by wizard_hu_ View Post
    As I understand you can not deploy files to the isolated storage. A thing you can certainly do is deploying them with the .xap, and save them into the isolated storage when you need to modify them.
    On the implementation side it affects the loader routine, you try to load data from the file first, and if the file does not exist, you turn to the resource.
    Understood now, well I am completely a new bee in WP7...
    Next issue then is: how to deploy a txt file...

    These are the steps I did to deploy the file:
    Create a NewFolder called Resources and placed my.txt inside it
    Clicked on the properties of "my.txt" and selected Content for Build Action.

    Problem being faced now: How to access it and read its content to string ?
    I am trying to use StreamReader, but not successful, here is the code:

    Code:
                StreamReader readFile = null;
    
                try
                {
                    readFile = new StreamReader("Resources\\IndiFontTest.txt");
                    //FileStream myFileStream = File.Open("Resources\\IndiFontTest.txt", FileMode.Open);
    
                    //readFile = new StreamReader(new File("Resources\\IndiFontTest.txt", FileMode.Open, myStore));
    
                    //readFile = new StreamReader(new IsolatedStorageFileStream("Resources\\IndiFontTest.txt", FileMode.Open, myStore));
                    string fileText = readFile.ReadToEnd();
    
                    //The control txtRead will display the text entered in the file
                    textBlockListTitle.Text = fileText;
                    readFile.Close();
                }
    
                catch
                {
    
                    textBlockListTitle.Text = "A - Need to create directory and the file first.";
    
                }
    I tried some options, but not aware how to access the file (location?) and then how to read from it...
    Amit Kankani
    Nokia Developer Champion

  10. #10
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Windows Phone and Access to Filesystem

    I am not familiar with WP7 either, but the link in #2, which is also repeated in #6 (and actually referred in the articles linked in #5 too) is a good starting point, really. How about opening it, and checking the How-to articles it offers just above the image?
    Otherwise you were close with the attempt, just missed the IsolatedStorageFile class and its static getter

  11. #11
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Windows Phone and Access to Filesystem

    Quote Originally Posted by wizard_hu_ View Post
    I am not familiar with WP7 either, but the link in #2, which is also repeated in #6 (and actually referred in the articles linked in #5 too) is a good starting point, really. How about opening it, and checking the How-to articles it offers just above the image?
    Otherwise you were close with the attempt, just missed the IsolatedStorageFile class and its static getter
    thanks for the reply, I actually did have a look, but cudn't get a way to find how to deploy a file and read it... All the links talk about how to create file storage and then read it....
    Will dig more and see if i get any pointers....
    Amit Kankani
    Nokia Developer Champion

  12. #12
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Windows Phone and Access to Filesystem

    Ah, we are talking about the .xap part then. It is Application.GetResourceStream as I understand, http://msdn.microsoft.com/en-us/libr...(v=VS.95).aspx, but I have not tried it in action.

  13. #13
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Windows Phone and Access to Filesystem

    Quote Originally Posted by wizard_hu_ View Post
    Ah, we are talking about the .xap part then. It is Application.GetResourceStream as I understand, http://msdn.microsoft.com/en-us/libr...(v=VS.95).aspx, but I have not tried it in action.
    Yes, this is what I was looking for... Did a little more digging for text files and not images, and the following code works good :

    Code:
                    Uri uri = new Uri("Resources/IndiFontTest.txt", UriKind.Relative);
                    StreamResourceInfo sri = Application.GetResourceStream(uri);
    
                    StreamReader streamReader = new StreamReader(sri.Stream);
                    textBlockListTitle.Text = streamReader.ReadToEnd();
    thanks for the pointers
    Amit Kankani
    Nokia Developer Champion

  14. #14
    Registered User
    Join Date
    Jan 2009
    Posts
    19

    Re: Windows Phone and Access to Filesystem

    Hi,
    Hope below link its better help.
    http://www.windowsphonegeek.com/tips...ave-text-files

  15. #15
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: Windows Phone and Access to Filesystem

    Quote Originally Posted by pravejnini View Post
    Hi,
    Hope below link its better help.
    http://www.windowsphonegeek.com/tips...ave-text-files
    thanks, but that is already there in post #2, #6....

    If you carefully read, what I was looking for is not storage, but an ability to embed a file, with some contents.
    I was able to achieve it from the link given bu wizard_hu_ in post #12

    hope u got what is the difference...
    Amit Kankani
    Nokia Developer Champion

Similar Threads

  1. 6630 and Filesystem Access (JSR-75)
    By snillfisk in forum Mobile Java General
    Replies: 0
    Last Post: 2004-11-09, 13:38
  2. Midlet to access the filesystem
    By pappago in forum Mobile Java General
    Replies: 1
    Last Post: 2002-09-05, 07:17
  3. midlet to access the FileSystem
    By pappago in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2002-09-03, 14:15
  4. Midlet to access the filesystem
    By pappago in forum Mobile Java General
    Replies: 1
    Last Post: 2002-09-03, 09:01
  5. midlet to access the FileSystem
    By pappago in forum Mobile Java General
    Replies: 1
    Last Post: 2002-09-03, 08:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×