If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Error in converting csv to html code

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-01-10, 14:36
nareshb nareshb is offline
Registered User
 
Join Date: Dec 2010
Posts: 9
Error in converting csv to html code

Hai,
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><>");
ObjectStream.Writer.Write(""):
while (ObjectStreamReader.Peek() > -1)
{
Line = ObjectStreamReader.ReadLine();
ObjectStreamWriter.WriteLine("<tr><td>" + string.Join("</td><td>", Line.Split('\t')) + "</td></tr>");

}
ObjectStreamWriter.WriteLine("</table></body></html>");




Thanks in advance

Last edited by nareshb; 12-01-10 at 17:38.
Reply With Quote
  #2 (permalink)  
Old 01-09-11, 14:34
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
Reply

Tags
c#.net, csvto html, stream reader, stream writer

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On