0

Good morning everyone. I wrote a very simple class in C# that generates an html file and return it in a string. I want to write a new class that will display this file in default browser. Could you tell me how can I do it?

public class Class1
{
    public string HTMLGen(int number)
    {
        var html = string.Format("<p>testing my {0} html code</p>", number);

        var xDocument = new XDocument(
            new XDocumentType("html", null, null, null),
            new XElement("html",
                new XElement("head"),
                new XElement("body",
                        XElement.Parse(html)
                    )
            )
        );

        var settings = new XmlWriterSettings
        {
            OmitXmlDeclaration = true,
            Indent = true,
            IndentChars = "\t"
        };

        using (var sw = new StringWriter())
        {
            using (var writer = XmlWriter.Create(sw, settings))
            {
                xDocument.WriteTo(writer);
            }

            return sw.ToString();
        }
    }
}
  • This might help. https://stackoverflow.com/questions/10989709/open-a-html-file-using-default-web-browser – Shelby115 Dec 27 '17 at 21:39
  • 1
    Possible duplicate of [Open a html file using default web browser](https://stackoverflow.com/questions/10989709/open-a-html-file-using-default-web-browser) – MechMK1 Dec 27 '17 at 21:41

0 Answers0