开发者

C# How to save Console.Writeline Outputs to HTML Format?

I have a program which outputs various results after greping strings from a log text file. The results are shown onto a command line console.

Therefore are there anyways to generate the various output results into a html based report?

What methods could be used to convert the outputs? HtmlTextWriter? What are the steps needed to convert the file?

May someone please advise on the codes to do so? Thanks!

The codes:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Diagnostics;
 using System.IO;
 using System.Text.RegularExpressions;
 using System.Web.UI; // The system is telling me that it does not exist in the namespace System.web....


        foreach (String r in lines.Skip(1))
        {
            String[] token = r.Split(',');

            String[] datetime = token[0].Split(' ');

            String timeText = datetime[4];

            Double rawSize = Convert.ToDouble(token[1]);

            Double fileSize = ((rawSize / 1024) / 1024);

            String actions = token[2];

            String fileName = token[7];

            if ((Path.GetExtension(token[7]).Contains(".exe") || (Path.GetExtension(token[7]).Contains(".msi"))))
            {

  开发者_JS百科              Console.WriteLine("The time for this array is: " + timeText);

                Console.WriteLine(token[7]);

                Console.WriteLine(actions);

                Console.WriteLine(fileSize);

                ProgramFilter(actions, k, fileName);

                x = 1;

                Console.WriteLine("================================================");

            }

}


HTML is a text based format, so you can simply output HTML.

There isn't anything that will simply convert text into HTML for you - you need to decide what the markup will be.

There are many options to do this:

  • Using ASP.NET as a template and reading the result
  • Using a StringBuilder to build up your HTML
  • Use HtmlTextWriter to build up the HTML
  • Convert the data to XML and transform it with XSLT

As for writing to a file - again, several ways to do this:

  • Using the File class
  • Using a FileStream
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜