Learn 2 CSharp 8

8. Open a text file and convert it into HTML file. (File operations/Strings) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace lrn2csharp8 { class Program { static void Main( string[ ] args ) { string file = ""; string html = "<html><head><title></title></head><body>{0}</body></htm>"; string textFile = ""; Console.WriteLine( "Input name of a file in the current directory to convert into an HTML document." ); Console.Write( ":" ); try { file = Console.ReadLine( ); FileStream fs = new FileStream( file, FileMode.Open, FileAccess.Read ); StreamReader sr = new StreamReader( fs ); while(!sr.EndOfStream) { string line = sr.ReadLine( ); if ( line.Length != 0 ) textFile += "<p>" + line + "</p>"; } sr.Close( ); StreamWriter sw = new StreamWriter( fs.Name + ".html" ); sw.Write( string.Format( html, textFile ) ); sw.Close( ); fs.Close( ); } catch ( Exception e ) { Console.WriteLine( "WTF?!?" ); } } } }

posted by dharh 2:14 AM Jan 30th, 2010



2011: 5 3 1
2010: 12 9 7 1
2009: 12 11 8 5
2008: 12 5 4 3 2 1
2007: 12 11 10 9 8 7 6 5 4 3 2 1
2006: 12 11 10 9 8 7 6 5 4 3 2 1
2005: 12 10 7 6
2004: 10 9 6 5 4 3 2 1