简体   繁体   中英

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"))))
            {

                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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM