locked
Where can i find my text files?

    Question

  • I am working in a xaml app and am trying to make a text file, and then open it in like note pad. My code does not give me any errors but I can't find the file any where. Here is what I have:

            async void test()
            {
                StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
                StorageFile sampleFile = await folder.CreateFileAsync("sample.txt", CreationCollisionOption.ReplaceExisting);
                await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "Swift as a shadow");
            }

    I don't know if I can't find it or it is just not being made. 

    Thank You for your time.

    • Moved by Kristin Xie Monday, February 02, 2015 8:41 AM move to appropriate forum
    Wednesday, January 28, 2015 9:35 PM

Answers

  • Hi,

    The file contain in C:\Users\v-jime\AppData\Local\Packages\<yourapppackage>/LocalState.

    where username is your user account name.

    yourapppackage is the app packageName which you can find in the store app Package.appxmanifest file:

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, February 02, 2015 9:11 AM
  • Hi TomatoMan,

    A better way to find where the StorageFile points is to examine its Path in the debugger after calling CreateFileAsync. The path Anne mentions is common, but it is not correct for all systems.

    It should exist for your original app so long as the app hasn't been removed. This isn't the appx package itself, this is the application data. The app package will be in the Package.InstalledLocation and is not writeable (in production- it may be for a test app running from the VS project directory).

    The app data location shouldn't be exposed to users, but is only available through the app. If you want the user to be able to find the document outside of the app then you should use a FileSavePicker to let the user choose where to save it.

    If you want to programmatically open the file you can call Launcher.LaunchFileAsync with the sampleFile StorageFile object.

    --Rob

    Thursday, February 05, 2015 9:49 PM
    Owner

All replies

  • Please check this link:

    https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localfolder

    This code should work, however I have not tried it.

    try

       {
          StorageFile sampleFile = await folder.GetFileAsync("sample.txt");
          String content= await FileIO.ReadTextAsync(sampleFile);
          
       }
       catch (Exception)
       {
          // Timestamp not found
       }

    Wednesday, January 28, 2015 11:39 PM
  • Hi Thardus22,

    Welcome to the MSDN forum!

    I am wondering what the type of your project is. This forum is to discuss C#, if your issue is about windows store or windows phone, I would move your thread to the corresponding forum, and I would recommend you go to the right forum for help.

    Thanks for your understanding.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, January 29, 2015 11:35 AM
  • (I'm Thardus22, had to make a new account for reasons(like I forgot my password and it locked me out))

    Thank You for your response, this is in Microsoft visual studio in a Xaml app written in C#, or at least I think that is the correct designation.  The top response was not very helpful because I run into the same problem of not knowing where the files are and in this case I don't know where that snip it of code is suppose to go to make it work. I think the code I posted makes a text file, but I just can't find the file any where, and I don't know where StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder; is. 

    Thursday, January 29, 2015 9:45 PM
  • If you are trying to write this file out to the Program Files folder (the location where the exe is located), then Vista, Win 7 and 8 are are going to redirect the file location to a virtual folder. Those O/S(s) are not going to allow the writing of any files in the Program Files folder or sub folders. 
    Thursday, January 29, 2015 10:04 PM
  • IDK if I'm trying to write it to the Program Files folder, IDK where it is trying to go, that's what I'm trying to find out.
    Friday, January 30, 2015 8:12 PM
  • https://technet.microsoft.com/en-us/library/ff716245.aspx

    Files needed by a program should be written to the above folder for the mentioned  O/S(s). To see it, you have to unhide the hidden folder.

    Friday, January 30, 2015 11:41 PM
  • Hi,

    The file contain in C:\Users\v-jime\AppData\Local\Packages\<yourapppackage>/LocalState.

    where username is your user account name.

    yourapppackage is the app packageName which you can find in the store app Package.appxmanifest file:

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Monday, February 02, 2015 9:11 AM
  • Thank You very much! I finally got it to work, I finally relyzed that in the C:\Users\v-jime\AppData\Local\Packages\ my package was missing. I made a new app and it worked. So now I have a new problem, I need this to work in my first App, not the new test one. Why is the package missing and how do I fix it? Also it seams like the app should not run if that package is gone? Any help would be useful. 

    Thursday, February 05, 2015 9:22 PM
  • Hi TomatoMan,

    A better way to find where the StorageFile points is to examine its Path in the debugger after calling CreateFileAsync. The path Anne mentions is common, but it is not correct for all systems.

    It should exist for your original app so long as the app hasn't been removed. This isn't the appx package itself, this is the application data. The app package will be in the Package.InstalledLocation and is not writeable (in production- it may be for a test app running from the VS project directory).

    The app data location shouldn't be exposed to users, but is only available through the app. If you want the user to be able to find the document outside of the app then you should use a FileSavePicker to let the user choose where to save it.

    If you want to programmatically open the file you can call Launcher.LaunchFileAsync with the sampleFile StorageFile object.

    --Rob

    Thursday, February 05, 2015 9:49 PM
    Owner