View Full Version : MS Access Database Contents into HTML Pages
11-07-2004, 03:40 PM
I have a database with one table. The table has two fields:
PageName has info like: ContactUs.htm the actual name of the page
PageCode: Has actual HTML code <html> ........etc </html>
It is working fine with asp, when I link to a page using parameters the HTML code is displayed with no problem.
The question is:
Is it possible using ASP to extract the information that is available in the database and actually create HTML pages in an external folder?
When ASP code runs:
1- It picks-up the PageName from the first record PageName Field
2- It picks-up the PageCode form the first record PageCodeField
3- Create an HTML page in an outside folder or a folder in the web
And so on,
So, if there are 50 records in the database, the ASP code will generate 50 Web pages.
If records 1 PageName field has a name: ContactUs.htm
The ASP code, takes the PageCode field, create an HTML page and save it as ContactUs.htm in a folder.
11-13-2004, 08:25 PM
Yes, it is possible to create files through ASP. You'll need to use the FileSystemObject. It's pretty handy and fairly simple. Permissions and ensuring security will probably be the most difficult part.
Here are a few links to get you started with the FSO...
Basically, you'll just dump that text field as the contents of the new file and save it with the specified name.
Take a look at those links and let me know if you run into any trouble.
11-22-2004, 05:13 AM
I tried the code, it works fine. It create files from a written text. My case is that I have in an Access database a table with two fields:
(This field has the name of the page, e.g: books.htm)
(This field has the actual HTML code in a memo field)
How can I use ASP to:
1- Loop between records.
2- Goes to record 1. Pick up the page name and make it the name of the file
3- Pick up the code of the page and put it as the content of the file.
The code picks up from the talbe books.htm and make it as the name of the external file. Then picks up the HTML code and makes it the contents of the external file. Finally, I'll get a file called books.htm in an external folder outside the database, and that file is by itself a complete htm page.
11-23-2004, 08:22 PM
Well, it's essentially the same as displaying the values from the database except that instead of writing them out for display in the browser, you're using them to define the file name and contents.
It might be easiest if you just get it setup as if you were going to display the results and then modify it from there. Here's how you would change it:
Dim strRootPath, objFS, objFile
'Get the physical path for the root directory and save it as a variable
strRootPath = Server.MapPath("/")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
'Open your database, call the records, then you can just include this code in your loop to create the text file
Set objFile = objFS.CreateTextFile(**PUT YOUR FILE NAME FROM DB HERE**, True)
objFile.Write (**PUT YOUR FILE CONTENTS FROM DB HERE**)
'the end of the loop comes down here
Does that help at all? Let me know how it goes...
11-29-2004, 09:07 AM
Got the idea, I'll try it.
This reminded me of something in which I need your guidance (links, documentation). I think it is related to FSO but in different manner.
I have a database for books, I created a search form and a page to display the results. It is working perfectly. The URL in the address bar is like this:
How can I convert this to:
This 65.htm is a generated html page and won't be saved.
Also if the user bookmarks the page when he/she requests it, how can I received his request and regenerate the page.
How can I do that in theory.
I searched the net for articles on this but could not find any in ASP.
Thank you NMJ
11-29-2004, 10:49 AM
Are you just wanting to change what the URL looks like or are you wanting to change how the page behaves? Is the 65.htm page static or does it actually pull info. from a database each time?
I'm just a little confused about what you're after...
11-29-2004, 11:14 AM
Thank you for your quick reply- that was quick indeed.
Yes you are right. Changing the page to .htm without saving it.
Have a link like this:
Will pick up the book which has this number 0735645301 from the database and displays the details.
Add books details to the database using AddTitle.asp
Title:Anatomy and Me
To view the book details it should be logically an ASP page like:
View.asp?BookID=0978746302 (the full URL will be)
Instead, this URL should appear
Even without .htm will do.
I hope it is clear now.
Thank you NMJ
Powered by vBulletin® Version 4.1.12 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.