Reading a txt file in vb for windows store app RRS feed

  • Question

  • I try developing a windows Store App using VB

    I want to read  the content of a text file "TextFile1.txt" which I created in Visual stdio 2013 RC and display the content in textblock "text1"

    i tried this code

    Private Sub Button_Tapped(sender As Object, e As TappedRoutedEventArgs)
            Dim folder As Windows.Storage.StorageFolder
            folder = Windows.ApplicationModel.Package.Current.InstalledLocation
            Dim file As StorageFile
            Dim prg As String
            file = StorageFile.GetFileFromPathAsync("ms-appx:///programs/TextFile1.txt")
            If file IsNot Nothing Then
                prg = FileIO.ReadTextAsync(file)
                text1.Text = prg
                prg = "empty"
            End If
        End Sub

    I get runtime error

    1. An exception of type 'System.ArgumentException' occurred in C_Programming.exe but was not handled in user code

    Additional information: The parameter is incorrect.

    WinRT information: Alternate stream names must begin with "app-".

    If there is a handler for this exception, the program may be safely continued.

    2. at 

    prg = FileIO.ReadTextAsync(file)

    Cannot be converted to string. I also tried giving the path name directly replacing the file but I get the same error.

    please help me.

    Thanx in advance.

    • Moved by Carl Cai Monday, November 4, 2013 1:38 AM more related
    Saturday, November 2, 2013 12:46 AM


All replies

  • Hi,

    I have moved this thread to Building Windows Store apps with C# or VB forum for more dedicated support.

    Thanks for your understanding.


    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.

    Monday, November 4, 2013 1:38 AM
  • Two issues:

    GetFileFromPathAsync requires a path and since it's Async you need to Await it.

    To use a URI like ms-appx use the GetFileFromApplicationUriAsync | getFileFromApplicationUriAsync method :

      file = Await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///programs/TextFile1.txt"))

    You'll also have to add an "Async" modifier to your function declaration. See Quickstart: Calling asynchronous APIs in  C# or Visual Basic for more information on asynchronous methods.

    Private Async Sub Button_Tapped(sender As Object, e As TappedRoutedEventArgs)


    • Proposed as answer by Dave SmitsMVP Monday, November 4, 2013 7:55 AM
    • Marked as answer by Anne Jing Friday, November 8, 2013 2:22 AM
    Monday, November 4, 2013 2:59 AM