Click to See Complete Forum and Search --> : Using HTML Template to create new htmls


OmriN
January 8th, 2008, 08:07 AM
Hi Everyone,

I need some help with a code i'm writing, though i'm not sure if
it's C# or asp.net related, i figure it's concerns them both.

i'm trying to build dynamic html page using input the user inserts
( like bgcolor, font style, and text).
for example: if the user chose "Center" if the web form than i want the
the title tag in the template to get "align='center'", i hope i'm making myself clear...

Today i'm working mainly with VB6 and there there's the option of using
WebClass tags inside the html page and replacing then from the code.

anyone know a way of doing this? if in asp.net there some other way i would be happy to learn it.

Thanks in advance

Omri

Yeorwned
January 9th, 2008, 11:01 AM
If you want it to actually create the file on the server, you need full access to the machine to make permission changes. You can use the data sent in forms to fill your predefined template and write the results to an html file via .net resources like System.IO.StreamWriter() and SaveAs()

Example of appending an existing file:

Dim file as String = "C:\Inetpub\"
Dim objStreamWriter as StreamWriter
objStreamWriter = File.AppendText(file)
objStreamWriter.WriteLine("<body bgcolor='" + request.form("bgcolor") + "'>" )
objStreamWriter.WriteLine("</body>")
objStreamWriter.Close()

OmriN
January 11th, 2008, 01:30 PM
thanks for the reply

i've started doing something similar to what you suggested but it seem not very efficient cause in this way i have to write all the html code through the c# code and it makes it hard to write and hard to make small adjustment....

i've searched for a way to use html template but so far all i've read is that in asp.net it's realy hard to do which is weird cause as i said before, in vb6 it's realy simple ( webitmes project).

i'll keep looking though

thanks again

Omri

Yeorwned
January 11th, 2008, 02:07 PM
If you want to make it easy to maintain, create the html file you want to generate and put it in a folder that asp.net can get to. Then, instead of writing out the file, have asp.net copy the template and open it. You could then use regular expressions to find the parts you want to change and save it back to the disc.

If you already have a solution, you're not going to save time right now by redoing it obviously but if you edit the page enough in the future or end up doing this again, the second solution might be something to consider. Alternatively, just be sure to use lots of comments and line breaks in your current code so you can find things in your template if you're having problems when it comes to editing the template.