0

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("================================================");

            }

}

JavaNoob
  • 3,494
  • 19
  • 49
  • 61
  • This depends on the complexity and format of your output. Do you need tables/divs and such stuff, or just plain text separated by line breaks that display in an html browser ? In the latter cas you could just use a StringBuilder insrting basic html tags and a FileStream Writer to .html format. – Mehdi LAMRANI Dec 18 '10 at 15:17

1 Answers1

1

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:

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • Yea but how do you use the HtmlTextWriter to do it? I've have seen the various examples but its not working. Edited the question please have a look. Thanks! – JavaNoob Dec 18 '10 at 15:21
  • @JavaNoob - I don't see any use of `HtmlTextWriter` in your code. Where do you intend to use it? I find `HtmlTextWriter` to be a fairly _low level_ API and not that friendly to use (might as well use `StringBuilder`, if you know your HTML). – Oded Dec 18 '10 at 15:28
  • Do you have any idea where to place the HtmlTxtWrite? The online community has recommended that HmtlTextWriter has a better usage but Im not sure. – JavaNoob Dec 18 '10 at 15:36
  • @JavaNoob - you can declare it at the top of the class and use it whenever you do a `Console.Write`. What online community? And yes, for HTML it would be better to use `HtmlTextWriter` (as it escapes correctly and writes attributes correctly etc...). I just meant is was almost as low level as `StringBuilder`. – Oded Dec 18 '10 at 15:39
  • Thanks for replying. So when I start a new project I can use the HtmlTextWriter for the console application in VS 2010 or must a .ASP Net application be used instead? As mentioned in the question, the Using System.Web.UI is showing me that the system does not recognize the namespace after the ".Web" to ".UI". I red this online "HTML is a string and it is easy to generate HTML using StringBuilder. However, that method is also prone to many bugs and can result in extremely complex syntax. Here we use the HtmlTextWriter class to alleviate these problems." – JavaNoob Dec 18 '10 at 15:45
  • @JavaNoob - `HtmlTextWriter` is just a way to write out HTML fragments (or whole documents, if you will). No need for ASP.NET or IIS. As for your quote - yes, HTML is a bit more complicated than just a string, so using a wrapper is advised. – Oded Dec 18 '10 at 15:47
  • Any ideas why the Using system.web.UI is not working? Its just saying that it does not exist in namespace "system.web"... – JavaNoob Dec 18 '10 at 15:51
  • @JavaNoob - it is `System.Web.UI`, not `system.web.UI`. – Oded Dec 18 '10 at 15:52
  • @JavaNoob - How did you use the classes in it? The `System.Web` dll contains that namespace, so it should work. Have you added a reference to that assembly? – Oded Dec 18 '10 at 15:57
  • Yep I followed the instructions on http://bytes.com/topic/c-sharp/answers/275652-system-web-ui-namespace but on the .net tab I only see the System.Web.Application and System.Web.Services. There is no System.web dll.... – JavaNoob Dec 18 '10 at 16:01
  • @JavaNoob - Then something is wrong. It should be there. Does it exist in the `%windir%\assembly` directory? – Oded Dec 18 '10 at 16:06
  • 1
    Its ok I found the solution. Just change the target to .Net 4 instead of .Net 4 Client and the dll would be available at the add reference menu. Thanks. – JavaNoob Dec 18 '10 at 16:08