Solved

file.writeline ASP stuff

Posted on 2001-07-11
36
291 Views
Last Modified: 2006-11-17
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!
0
Comment
Question by:ClassyLinks
  • 16
  • 13
  • 6
  • +1
36 Comments
 
LVL 7

Expert Comment

by:daniel_c
ID: 6274767
file.WriteLine "<title><%=rs('title')%></title>"
--> This is correct.
So, what's the problem?
0
 
LVL 3

Expert Comment

by:phuctran
ID: 6274769
(listening)

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

0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6274775
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 6274777
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
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6274804
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6274821
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 6274825
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
 
LVL 20

Expert Comment

by:jitganguly
ID: 6274829
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6274833
Oh c'mon Jit.... you didn't even reply me in Yahoo messenger... :D
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6274836
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
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6274864
Go ahead Jit...have a good evening.
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6274924
daniel....

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

Am I missing something??
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6274960
hmm... it's weird! Is it from my example or in your code?
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6274964
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
 
LVL 7

Accepted Solution

by:
daniel_c earned 100 total points
ID: 6275000
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
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6275016
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6275058
Got it!
You just changed in %> not in <%.
You have to change in each %!

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

0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6275080
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 7

Expert Comment

by:daniel_c
ID: 6275081
What!? no text?
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6275085
hmm... so strange! I paste your code here, and it didn't work?
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6275088
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6275090
{ sigh } give up! No Text.

If you want the code, give me your email and i'll send you your fix-code!
:)
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6275098
truely??  messyscripts@classylinks.ca

You're a life saver!
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6275145
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6275156
Oopss... okay, let me fix it!
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6275241
FANTASTIC!

Thank you very much!
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6275292
Happy to be able to help expert woman like you Classy! :)
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6275304
LOL...hardly expert!  Not today anyway.  ;-)
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6277346
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6278109
Got you now in IM Jit! :-)
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6278176
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
 
LVL 7

Expert Comment

by:daniel_c
ID: 6278292
Sounds will be a great tool!
Classy's ASP Generator or something?

^_^
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6278302
Something like that  ;-)

Not really an asp generator though.  Do you want to hear the full story?
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6278303
Cool Classy,
Now I won't write ansy ASP pages. just fill in the blanks and BOOM
:-)
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6278308
GO ahead classy
0
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6278370
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now