2

I have to create a bunch of static html files as console / winform job. The current solution uses a string builder. Having used ASP.NET-MVC with strongly typed view pages (System.Web.Mvc.ViewPage) I was wondering if it is possible to leverage these view pages and have them output to a stream or file without building an ASP.NET solution.

Essentially I'd like to create the viewpage, pass in the strongly typed object, and render the result.

I'm also open to other view engines.

If this ends up requiring bringing over the whole kitchen sink, then I can just do a string builder style.

Thanks.

anonymous
  • 6,825
  • 8
  • 47
  • 60
  • I am not sure I understand the question fully, why are you not looking more towards an XSLTish solution and be flexible on how your winform/console job does the rendering? – Perpetualcoder May 27 '09 at 16:04
  • maybe look at this? http://www.codeproject.com/KB/XML/XML_to_HTML_Convertor.aspx – Perpetualcoder May 27 '09 at 16:08
  • Yah.... I guess I wanted to use an ASP ViewPage because I know it and the designer is helpful for html. But those two reasons seem kinda weak :) – anonymous May 27 '09 at 16:51
  • Okay... I wanted to close the question but none of the options seem to fit, so maybe I'm supposed to leave it open. Anyways, I don't like this question anymore as it makes me feel stupid :) – anonymous May 27 '09 at 16:53

3 Answers3

5

Note sure if this helps as I was unclear about your question.

[ControllerAction]
public void About()
{
    StringWriter builder = new StringWriter();
    TextWriter originalWriter = Response.Output;
    Response.SwitchWriter(builder);
    RenderView("About");

    string html = builder.ToString();

    originalWriter.Write(html);
}
David
  • 15,150
  • 15
  • 61
  • 83
  • I'm sorry, I wasn't very clear. I wasn't sure how to phrase it. I don't want to build an actual website... I just want a console application to spit out html files. I was hoping to use the built in ASP.NET ViewPage (specifically Mvc strongly typed ones) as my template to create these html files. – anonymous May 27 '09 at 16:43
  • I do like your solution though... that is good to know for other things :) +1 ! – anonymous May 27 '09 at 16:53
3

I personally like the StringTemplate option mentioned above, but you can actually host the ASP.NET runtime in a desktop application.

Rick Strahl over at West Wind Technologies has a detailed example of how to set it up: Using the ASP.Net Runtime for extending desktop applications with dynamic HTML Scripts

Here are a couple of other examples:

GuyIncognito
  • 1,246
  • 11
  • 11
2

What you need is a templating engine. I would recommend you StringTemplate. It can be used as standalone engine and it has a .NET version. There's a CodeProject article that could get you started.

AFAIK ASP.NET WebForms cannot run without the ASP.NET infrastructure.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • See http://stackoverflow.com/questions/2394724/can-i-run-a-aspx-and-grep-the-result-without-making-http-request – DuckMaestro Mar 11 '11 at 23:11