file.writeline ASP stuff

Hi all!

jitganguly passed a script on to me this morning to enable me to create files on the fly.

It works great!

However, I want to be able to insert asp code and not have it parse.

For example, I want to put in:

file.WriteLine "<title><%=rs('title')%></title>"
and have it write that way to the file instead of parsing the ASP.

The reason for this is that I am setting up template pages where the pages will be ASP and pull from a database.

Any idea if this syntax is correct??  

jitganguly's code works entirely on direct querystrings to the page from the form, but I need to write to the database first, then just create the blank ASP page, and let the database fill in the blanks.

Does this make any sense??

Thanks to all who help!
LVL 7
ClassyLinksAsked:
Who is Participating?
 
daniel_cConnect With a Mentor Commented:
If you are using Find and Replace, then try to use:
& chr(asc("%")) & 

So:
Find: %
Replace: " & chr(asc("%")) & "

Hopefully it works now!

Cheers,

Daniel

0
 
daniel_cCommented:
file.WriteLine "<title><%=rs('title')%></title>"
--> This is correct.
So, what's the problem?
0
 
phuctranCommented:
(listening)

haven't tried this but how about
file.WriteLine Server.HTMLEncode("<title><%=rs('title')%></title>")

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
ClassyLinksAuthor Commented:
I was asking if it was correct daniel.  I'm worried that the %> at the end of rs('title') will close the asp scripting prematurely.

phuctran....does Server.HTMLEncode work with file.WriteLine??
0
 
jitgangulyCommented:
It implies she didn't like jitganguly's code :-)


OK, classy ,
Create a db table and insert values based on form fields of the first page i.e. the page which has forms (htmlpagebuilder.asp)
Now in process page do teh db updation first and then the file.writelien stuff
0
 
ClassyLinksAuthor Commented:
right Jit....I've done the update first  (and I love your code..I just need to "tweak" it  8-)

But the writeline stuff...how do I write including <% and %> in what gets written?

I want the resulting page to have <title><%=rs('title')%></title> so that when it is called from the browser THEN it gets parsed.  I don't want to create an HTML page, but an asp page, which will be edited later by changing these db field values.
0
 
daniel_cCommented:
Oopss... yes, Classy is right. It didn't work.

Okay, one trick I've used is to find "%" and replace it with chr(asc("%")).

Here is the snippet:
<%
     set fso               = Server.CreateObject("Scripting.FileSystemObject")
     set     f               = fso.OpenTextFile("C:\test.txt", 8, True) ' 8 = ForAppending    
     f.WriteLine("<a href=<" & chr(asc("%")) & "=rs('abc')" & chr(asc("%")) & ">Test</a>")
     f.close
     set f = nothing    
     set fso = nothing

%>

Hope that helps!

:)
0
 
jitgangulyCommented:
You will do somethign like this

'db updates etc.
'like connections
' recordset
and then

 file.WriteLine "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"
 file.WriteLine CHR(13)
 file.WriteLine "<html>"
 file.WriteLine "<head>"
' Note the following two line
' puttign the asp tag <% withinh the string
 file.WriteLine "<%" & RS("headstring") & "%>"
 file.WriteLine "<title><%" & RS("Titlestring") & "%> </title>"


0
 
jitgangulyCommented:
May I take off for the day ? Its 5.30 now.Hope my last suggestion will  work, otherwise Mr. Daniel can help you
Have fun
0
 
daniel_cCommented:
Oh c'mon Jit.... you didn't even reply me in Yahoo messenger... :D
0
 
ClassyLinksAuthor Commented:
I'll try that daniel..

Jit...file.WriteLine "<title><%" & RS("Titlestring") & "%> </title>"...won't that try to parse the titlestring in our page action.asp??
0
 
ClassyLinksAuthor Commented:
Go ahead Jit...have a good evening.
0
 
ClassyLinksAuthor Commented:
daniel....

I'm getting Invalid character on the % in the string chr(asc("%"))

Am I missing something??
0
 
daniel_cCommented:
hmm... it's weird! Is it from my example or in your code?
0
 
daniel_cCommented:
I mean have you applied it into your application?
If you have, then just copy the statement which brought the error message, and paste it here.
0
 
ClassyLinksAuthor Commented:
I got around it by doing this:

& chr(asc('%'))&>

But now...nothing is being written to the resulting file

The file is created and the values go into the db, but the html/asp is not written to the new page.

Here is the code that is supposed to write to it.

file.WriteLine "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"
file.WriteLine CHR(13)
file.WriteLine "<html>"
file.WriteLine "set conn = server.createobject('adodb.connection')"
file.WriteLine "conn.ConnectionString='Provider=Microsoft.Jet.OLEDB.4.0; Data Source=' & Server.MapPath('database/echodomains.mdb')&';'"
file.WriteLine "conn.open"
file.WriteLine "sql = ""SELECT * FROM tblDomains WHERE DomainName = &FolderName&"""
file.WriteLine "set rs = conn.execute(sql)"
file.WriteLine "<head>"
file.WriteLine Request("Headstring")
file.WriteLine "<title><%=rs('title')& chr(asc('%'))&>"
file.WriteLine "BODY {background-color: <%=rs('background')& chr(asc('%'))&> ; background-image:none}"
file.WriteLine "H1 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font')& chr(asc('%'))&> }"
file.WriteLine "H2 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font')& chr(asc('%'))&> }"
file.WriteLine "H3 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font')& chr(asc('%'))&> }"
file.WriteLine "H4 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font')& chr(asc('%'))&> }"
file.WriteLine "H5 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font')& chr(asc('%'))&> }"
file.WriteLine "H6 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font')& chr(asc('%'))&> }"
file.WriteLine "P {color: <%=rs('textColour')>; font-family:<%=rs('font')& chr(asc('%'))&> }"
file.WriteLine "A:hover {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: #898C57; text-decoration:none}"
file.WriteLine "A:link {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: maroon; text-decoration:none}"
file.WriteLine "A:visited {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: maroon; text-decoration:none}"
file.WriteLine "A:visited:hover {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: #898C57; text-decoration:none}"
file.WriteLine "li {color: goldenrod}"
file.WriteLine "<table align = """ & Request("TableAlignstring") & """ Border=""" & Request("TableBorderstring") & """ cellspacing="""& Request("TableCellSstring")& """cellpadding="""& Request("TableCellPstring")& """ colspan=""" & Request("TableColSpanstring")& """>"
for i = 1 to Request("TotRowstring")
file.WriteLine "<tr align= """ & Request("RowAlignstring") & """ valign=""" & Request("RowVAlignstring") & """ width="""& Request("Rowwidthstring")& """>" 
for j = 1 to Request("TotColstring")      
file.WriteLine "<td align= """ & Request("colAlignstring") & """ valign=""" & Request("colVAlignstring") & """ width="""& Request("Colwidthstring")& """>" 
file.WriteLine "</td>"
next      
file.WriteLine "</tr>"
next
file.WriteLine "</table>"
file.close


Can you see what I am doing wrong??
0
 
daniel_cCommented:
Got it!
You just changed in %> not in <%.
You have to change in each %!

Find: %
Replace: " & chr(asc("%")) & "

0
 
daniel_cCommented:
0
 
daniel_cCommented:
What!? no text?
0
 
daniel_cCommented:
hmm... so strange! I paste your code here, and it didn't work?
0
 
daniel_cCommented:
0
 
daniel_cCommented:
{ sigh } give up! No Text.

If you want the code, give me your email and i'll send you your fix-code!
:)
0
 
ClassyLinksAuthor Commented:
truely??  messyscripts@classylinks.ca

You're a life saver!
0
 
ClassyLinksAuthor Commented:
Thanks Daniel....great!

just one little problem....this is what it is writing to the new page:

<title><%=rs('title')& chr(asc('%'))&>
BODY {background-color: <%=rs('background')& chr(asc('%'))&> ; background-image:none}
H1 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font') & chr(asc('%'))&> }
H2 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font') & chr(asc('%'))&> }
H3 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font') & chr(asc('%'))&> }
H4 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font') & chr(asc('%'))&> }
H5 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font') & chr(asc('%'))&> }
H6 {color: <%=rs('headerColour')& chr(asc('%'))&> ; font-weight:bold; font-family:<%=rs('font') & chr(asc('%'))&> }
P {color: <%=rs('textColour')>; font-family:<%=rs('font')%> }
A:hover {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: #898C57; text-decoration:none}
A:link {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: maroon; text-decoration:none}
A:visited {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: maroon; text-decoration:none}
A:visited:hover {font-weight: bold; font-family:<%=rs('font')& chr(asc('%'))&> ; font-size:x-small; color: #898C57; text-decoration:none}
li {color: goldenrod}
<table align = "" Border="" cellspacing=""cellpadding="" colspan="">
</table>


(That is the actual HTML code in the created page)

So  have to strip those asc's again and turn them back into %>
0
 
daniel_cCommented:
Oopss... okay, let me fix it!
0
 
ClassyLinksAuthor Commented:
FANTASTIC!

Thank you very much!
0
 
daniel_cCommented:
Happy to be able to help expert woman like you Classy! :)
0
 
ClassyLinksAuthor Commented:
LOL...hardly expert!  Not today anyway.  ;-)
0
 
jitgangulyCommented:
Back today.
Classy ,
Great, Could you send me the code (if not copyrighted etc. etc.) to jit_ganguly@yahoo.com

Daniel,
I never got your IM. You can email me at jit_ganguly@yahoo.com. I am in touch with Dave,Mark etc from EE

Rgds
Jit
0
 
daniel_cCommented:
Got you now in IM Jit! :-)
0
 
ClassyLinksAuthor Commented:
Sure Jit...I'll send it to you....I'm just in the process of changing the form page.....I'm making it so that it creates an asp page with modifable style sheets.  Can you wait until I have those elements finished?
0
 
daniel_cCommented:
Sounds will be a great tool!
Classy's ASP Generator or something?

^_^
0
 
ClassyLinksAuthor Commented:
Something like that  ;-)

Not really an asp generator though.  Do you want to hear the full story?
0
 
jitgangulyCommented:
Cool Classy,
Now I won't write ansy ASP pages. just fill in the blanks and BOOM
:-)
0
 
jitgangulyCommented:
GO ahead classy
0
 
ClassyLinksAuthor Commented:
The whole story:

All this page is really doing is creating pages which will fill in their data based on database info.

There will be 5 templates the user can choose from.  The will have all the ASP requests for recordset info built in.

What this page is doing is #1 creating a directory for the page to live in, #2 creating the default page (which is all I'm worried about at the moment, #3 sending me an email to create the DNS entry for the sub-domain, #4 letting the client choose colours/styles which are then sent to the db and called on the created page using CSS, #5 allowing the client to fill in a text box with all their text/layout info, which may or may not include HTML tags too.

This is going to be used on a community portal I am working on for starters.  The community is selling these one page 3rd level domains.  As with everything else, there are many levels to "upsell".  The page created with this "wizard" is the basic level.  If a customer wants more all they need to do is create the page themselves (or hire me!) and upload it.

If they stick with the basic level, they can then login to a page and change their colour/values/text via the browser and the changes to their site are instantaneous.  If they upgrade....well, it costs them more, naturally and the changes/upgrades are their responsibility.

Does this make sense?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.