locked
c# windows store app exception when reading text

    Question

  • Guys

    I keep getting a the exception 'System.ArgumentOutOfRangeException' with he following line of code

    var Lines = await Windows.Storage.FileIO.ReadTextAsync(file);

    I presume its because there is a limit to how much text can be read into the string Lines as it worked ok untill i added more text to the file once it is read into the string I then use split to put each line into an array

    The file is a text file and its is made up of 500+ lines of text which will grow to about 3000 so I need a way of reading these

    I need to store each line in an array

    This is he code I use at the moment

                         

    string filepath = @"Assets\DATA.csv";
                StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                StorageFile file = await folder.GetFileAsync(filepath); // error here
                var Lines = await Windows.Storage.FileIO.ReadTextAsync(file);
                 string[] lines2 = Lines.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

    It reads the file from the assets directory into a string and then splits it to an arrayis the a way of reading each line and putting it directly into an arrayEach line is terminated by a newlineAny help appreciatedMark

    • Edited by wambaugh1 Tuesday, February 3, 2015 11:25 PM
    Tuesday, February 3, 2015 10:39 PM

Answers

  • Since you're splitting into lines anyway, Does FileIO.ReadLinesAsync work for you any better?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, February 4, 2015 1:01 PM
    Moderator