Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010

    Unanswered: Error in converting csv to html code

    I am trying to convert csv to html by using stream reader and writing that into stream writer the problem is it is missing the last line of the csv file i debugged and tried tracing stream reader but i am unable see stream reader output in the watch at each loop .

    string Line, path = @"C:\Vertex\nov\Source\Reports\Rpt_Disconn_and_Rec onn_List_for_Customer_Operations_Results.csv";

    System.IO.StreamReader ObjectStreamReader = null;
    System.IO.StreamWriter ObjectStreamWriter = null;

    ObjectStreamReader = new System.IO.StreamReader(path);
    ObjectStreamWriter = new System.IO.StreamWriter("result.html");

    Line = ObjectStreamReader.ReadLine();
    ObjectStreamWriter.Write("<html><head><table border =1><>");
    while (ObjectStreamReader.Peek() > -1)
    Line = ObjectStreamReader.ReadLine();
    ObjectStreamWriter.WriteLine("<tr><td>" + string.Join("</td><td>", Line.Split('\t')) + "</td></tr>");


    Thanks in advance
    Last edited by nareshb; 12-01-10 at 18:38.

  2. #2
    Join Date
    Nov 2003
    Christchurch, New Zealand
    Check your CSV file. Is there actually a carriage return at the end of the file (eg chr(13) + chr(10))?

    I haven't used the stream reader for a while but I imagine that would cause the problem you are referring to. Instead of the EOL code it is getting the EOF code at the end of the line so not recognising the last line as valid.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts