locked
[UWP]Additional information: Could not find a part of the path 'c:\Assets\Testing.txt'. RRS feed

  • Question

  •  var filestream = new System.IO.FileStream("/Assets/Testing.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                using (StreamReader sr = new StreamReader(filestream, true))

                {
                    String line = sr.ReadLine();
                }

    Error: filestream got null and Could not find a part of the path 'c:\Assets\Testing.txt'.. I don't understand about c:\. I have saved it in Assets.

                
    • Edited by Barry Wang Monday, March 14, 2016 8:37 AM title tag
    Sunday, March 13, 2016 2:33 AM

Answers

  • To access files in your app your should the ms-appx protocol. You might also want to consider using StorageFile too. E.g.

    http://lunarfrog.com/blog/winrt-folders-access


    http://pauliom.wordpress.com

    • Proposed as answer by Barry Wang Monday, March 21, 2016 2:37 AM
    • Marked as answer by Barry Wang Tuesday, March 22, 2016 1:22 AM
    Sunday, March 13, 2016 6:15 AM
  • Hello Le Thien Hoang,

    If you want to access via URI you need to use the following code:

     Uri uri = new Uri("ms-appx:///Assets/Testing.txt");
                var file =await StorageFile.GetFileFromApplicationUriAsync(uri);

    Please notice that in UWP you'd better switch to use StorageFile instead of System.IO.FileStream as suggested by pkr2000. The installed location is some place not like the classic desktop app. It is in a sandbox.

    Best regards,

    Barry


    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.


    • Edited by Barry Wang Monday, March 14, 2016 8:38 AM
    • Proposed as answer by Barry Wang Monday, March 21, 2016 2:37 AM
    • Marked as answer by Barry Wang Tuesday, March 22, 2016 1:22 AM
    Monday, March 14, 2016 8:36 AM

All replies

  • To access files in your app your should the ms-appx protocol. You might also want to consider using StorageFile too. E.g.

    http://lunarfrog.com/blog/winrt-folders-access


    http://pauliom.wordpress.com

    • Proposed as answer by Barry Wang Monday, March 21, 2016 2:37 AM
    • Marked as answer by Barry Wang Tuesday, March 22, 2016 1:22 AM
    Sunday, March 13, 2016 6:15 AM
  •  var filestream = new System.IO.FileStream("ms-appx://Assets/Testing.txt",

     var filestream = new System.IO.FileStream("ms-appx:///Assets/Testing.txt",

    I got error again.

    error: doesn't support fomart...

    Monday, March 14, 2016 5:42 AM
  • please read the link

    http://pauliom.wordpress.com

    Monday, March 14, 2016 6:19 AM
  • Hello Le Thien Hoang,

    If you want to access via URI you need to use the following code:

     Uri uri = new Uri("ms-appx:///Assets/Testing.txt");
                var file =await StorageFile.GetFileFromApplicationUriAsync(uri);

    Please notice that in UWP you'd better switch to use StorageFile instead of System.IO.FileStream as suggested by pkr2000. The installed location is some place not like the classic desktop app. It is in a sandbox.

    Best regards,

    Barry


    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.


    • Edited by Barry Wang Monday, March 14, 2016 8:38 AM
    • Proposed as answer by Barry Wang Monday, March 21, 2016 2:37 AM
    • Marked as answer by Barry Wang Tuesday, March 22, 2016 1:22 AM
    Monday, March 14, 2016 8:36 AM