Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Advanced ASP Code - Generating Pages


  • Please log in to reply

#1
Immortalarena

Immortalarena

    Member

  • Member
  • PipPipPip
  • 211 posts
I am helping an organization with a website, and one of the things that they have on their site is an admin section that would allow an admin to create a new web page. In this it only asks for 4 things:

Page Display name (how it will appear in the database)
Page Title (The Title line for the HTML Page)
Page file name (something like newpage.asp)
Menu Type (Pulls navigation code for left frame)

This is supposed to generate a new ASP File on the root directory that includes the title, display name, and menu. The problem is that this doesn't work. It makes the Database entry, but does not generate the ASP file.

The code for the Generated Page to contain is:
[codebox]<%
Option explicit
dim sTitle
dim sCurrentPage
dim objRS
dim sMenu
sCurrentPage = "default"
sTitle = "default"
sMenu = "all"
%>
<!-- #include file="./includes/functions.asp"-->
<!-- #include file="./includes/dbconn.asp"-->
<!-- #include file="./includes/header.asp"-->
<%'main content for this page goes here

set objRS = DBConn.execute("select * from page where pagename = '"&sCurrentPage&"';")
while not objRS.eof
Response.Write(objRS("PageContent"))
objRS.movenext
wend
objRS.close
set objRS = Nothing
DBConn.close
set DBConn = nothing
%>
<!-- #include file="./includes/footer.asp"-->[/codebox]

The Three Values :
sCurrentPage = "default"
sTitle = "default"
sMenu = "all"
are the three that are changed when the new page is generated.

The Page that Edits the document and asks for the variables is:
[codebox]
<%Option explicit%>
<%'Functions site only contains sMenu code for each option%>
<!-- #include file="../includes/functions.asp"-->
<%'Connects to the Access Database%>
<!--#include file="../includes/dbconnupone.asp"-->
<%
dim sTitle
dim sCurrentPage
dim sMenu
dim i
dim sNewEntryName
dim sNewEntryDesc
dim objRS
dim objRS2
dim sDelete

Sub ManipFiles(destinationfilename, PageTitle, PageMenu, PageName)
Dim fso, f2
Set fso = server.CreateObject("Scripting.FileSystemObject")
Set f2 = fso.GetFile(server.MapPath("..\autopages\leavemehere.asp"))
'Response.Write "Copying file to c:\temp <br>"
' Copy the file to \temp.
f2.Copy (server.MapPath("..\autopages\" & destinationfilename))
'now open the file that we just copied and edit it
set f2 = fso.OpenTextFile(server.MapPath("..\autopages\" & destinationFilename), 1)
dim pagecontents
pagecontents = f2.readall
f2.close()

'frist replace the title
pagecontents = replace(pagecontents, "sTitleGoesHere", PageTitle)
pagecontents = replace(pagecontents, "sCurrentPageGoesHere", PageName)
pagecontents = replace(pagecontents, "sMenuGoesHere", PageMenu)



set f2 = fso.OpenTextFile(server.MapPath("..\autopages\" & destinationFilename), 2)
f2.write(pagecontents)
f2.close

End Sub
sTitle = "Troop101.net Administration"
sCurrentPage = "admin"
sMenu = "admin"
%>
<!-- #include file="../includes/headerupone.asp"-->
<span class=black11>
Logged in as <%=session("auth")%>&nbsp;&nbsp;
<a href="./logout.asp">Logout</a> or
<a href="./admin.asp">Back to the Admin Menu</a></span>
<br><br><span class=black11>Use this page to add new pages to the database
<br><br>
<br>
<form action=addpage.asp method=post id=form3 name=form3>
<table>
<tr>
<td class=black11 colspan=2><b>Add a new page</b></td>
</tr>
<tr>
<td class=black11>Page Display Name:</td>
<td><input type=text size=30 maxlength=100 name=txtNewAlbum class=black11></td>
</tr>
<tr>
<td class=black11>Page Title:</td>
<td><input type=text size=30 maxlength=100 name=txtPageTitle class=black11></td>
</tr>
<tr>
<td class=black11>Page File Name:</td>
<td><input type=text size=30 maxlength=100 name=txtPageFile class=black11></td>
</tr>
<tr>
<td class=black11>Menu Type:</td>
<td>
<select class=black11 name=menutype>
<option value="default">None</option>
<option value="troop">Troop</option>
<option value="pack">Pack</option>
<option value="crew">Crew</option>
<option value="alumni">Alumni</option>
<option value="eagle">Eagle</option>
<option value="all">All</option>
</select>
</td>
</tr>
<tr>
<td colspan=2><input type=submit value="Add Page" id=submit3 name=submit3></td>
</tr>
</table>
</form>


<!-- #include file="../includes/footer.asp"-->
[/codebox]

The only other linked page: leavemehere.asp contains the same code as the first box, but with the values sCurrentPageGoesHere, sTitleGoesHere, and sMenuGoesHere in the three containters, exampled below:
[codebox]<%
Option explicit
dim sTitle
dim sCurrentPage
dim objRS
dim sMenu
sCurrentPage = "sCurrentPageGoesHere"
sTitle = "sTitleGoesHere"
sMenu = "sMenuGoesHere"
%>
<!-- #include file="./includes/functions.asp"-->
<!-- #include file="./includes/dbconn.asp"-->
<!-- #include file="./includes/header.asp"-->
<%'main content for this page goes here

set objRS = DBConn.execute("select * from page where pagename = '"&sCurrentPage&"';")
while not objRS.eof
Response.Write(objRS("PageContent"))
objRS.movenext
wend
objRS.close
set objRS = Nothing
DBConn.close
set DBConn = nothing
%>
<!-- #include file="./includes/footer.asp"-->[/codebox]

Any help or suggestions are greatly appreciated.

The Database Fields are:
PageNum (The Primary index)
PageName (Page name as it appears for editing, and how it is pulled to be displayed.)
PageContent (The Content of the page, blank when a page is created)

I look forward to reply's. Thanks,

-Matt McCracken

P.S. This code was written in early 2000. If you know of a better way, please let me know. I am willing to use Javascript or another language to get this done, as long as my pages can remain .asp, and the Session state auth=admin can be used to keep unwanted visitors from making pages. Thanks!

Edited by Immortalarena, 25 March 2009 - 04:49 PM.

  • 0

Advertisements


#2
Immortalarena

Immortalarena

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 211 posts
I finally fixed this problem on my page. I had to give write permissions to the directory, then I had to actually put the template ASP file in the main directory, then the code seems to work great. If someone ever needs this the code works, just needs permissions and to know where you want the file to go appropriately. Thanks!
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP