Osman Villi
Osman Villi

Reputation: 346

Large text reading in asp.net

This is my asp.net code behind:

  public string ReadJSON(string jsonPath)
    {
        FileStream fs = new FileStream(jsonPath, FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs);
        string WillReturn = "";

        try
        {
            WillReturn = sr.ReadToEnd();
            return WillReturn;
        }
        catch (Exception ex)
        {

            WillReturn = null;
            return WillReturn;
        }
        finally { sr.Close(); fs.Dispose(); }
    }

But my data is 128 mb. And I am not taking error but no read. I tried to debuging. WillReturn = sr.ReadToEnd(); context is: WillReturn could not evaluate expression.

How can I read to this?

Upvotes: 0

Views: 86

Answers (1)

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38663

It can read 127Mb text file into rows in 2 minutes 30++ seconds. Try this sample code

strFileName = ViewState("Physical path");
StreamReader sr = new StreamReader(strFileName);


do {
    line = sr.ReadLine();



    if ((line != null)) {

        result = line.Split(Convert.ToChar(Constants.vbTab));
        icount += 1;


        dr = ds1.Tables(0).NewRow;


        dr.BeginEdit();
        dr("Item1") = result(0);


        ds1.Tables(0).Rows.Add(dr);
    }
} while (!(line == null));

Upvotes: 1

Related Questions