PDA

View Full Version : MS Access Database Contents into HTML Pages



hhammash
11-07-2004, 03:40 PM
Hi,

I have a database with one table. The table has two fields:

PageName
PageCode

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?

Example:
--------
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.

Thank you

no_mac_jack
11-13-2004, 08:25 PM
Hi, Hisham!

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...

http://www.w3schools.com/asp/asp_ref_filesystem.asp
http://www.4guysfromrolla.com/webtech/faq/FileSystemObject/faq1.shtml

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.

~no_mac_jack

hhammash
11-22-2004, 05:13 AM
Hi NMJ,

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:

PageName
(This field has the name of the page, e.g: books.htm)
PageHTML
(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.

Example:
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.

Thank NMJ.

no_mac_jack
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**)
objFile.Close

'the end of the loop comes down here

Does that help at all? Let me know how it goes...

~no_mac_jack

hhammash
11-29-2004, 09:07 AM
Hi NMJ,

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:

http://www.OurLibraryWeb.com/Books/ViewBooks.asp?BookID=65
How can I convert this to:
http://www.OurLibraryWeb.com/Books/65.htm

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

no_mac_jack
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...

~no_mac_jack

hhammash
11-29-2004, 11:14 AM
Hi NMJ,

Thank you for your quick reply- that was quick indeed.

Yes you are right. Changing the page to .htm without saving it.

Example:
--------

Have a link like this:

http://www.SiteName.com/EBooks/0735645301.htm

Will pick up the book which has this number 0735645301 from the database and displays the details.

Another example:
-----------------
Add books details to the database using AddTitle.asp

Title:Anatomy and Me
BookID=0978746302
Authoer=Somebody
Publisher=Some Publisher
...etc

To view the book details it should be logically an ASP page like:
View.asp?BookID=0978746302 (the full URL will be)
http://www.SiteName.com/EBooks/View.asp?BookID=0978746302
Instead, this URL should appear
http://www.SiteName.com/EBooks/0978746302.htm

Even without .htm will do.

I hope it is clear now.

Thank you NMJ