locked
reading text file from user Documents

    Question

  • I got this code for reading a text file in W8 C#/XAML technology.

     public async void ReadTextFile()
            {
                var file = await KnownFolders.DocumentsLibrary.GetFileAsync("copy.txt");
    
                var fs = await file.OpenAsync(FileAccessMode.Read);
                var str = fs.GetInputStreamAt(0);
                
                var reader = new DataReader(str);
                uint fileLength = await reader.LoadAsync((uint)fs.Size);
                string content = reader.ReadString(fileLength);
            }
        }
    Now I need the HTML5/Javascript counterpart, I just need to read a text file from the user Documents (my Documents folder in the test application). The file is a XHTML file (maybe it is straightforward for Javascript code), so I ask also what permissions I have to ask.

    Thanks in advance

    Tuesday, April 3, 2012 8:49 AM

Answers

  • Take a look at the File access sample. Scenario two demonstrates reading from a text file with Windows.Storage.FileIO.readTextAsync.

    You will need the Documents capability to read from the Documents library and the File Type Association declaration for .txt files. Both of these are demonstrated in that sample.

    --Rob

    Tuesday, April 3, 2012 5:37 PM
    Owner