Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic html pages 1

Status
Not open for further replies.

Niphyr

Programmer
Jul 21, 2003
85
AU
Is it possible for me to have a web page, and make is that it say, loads part of the text on the page from a text file. What i am trying to do is have my navigation load up form a text file, so that when i want to update it i update the one file, not each page on the whole site.

Im not too sure on ho to go about this, not even sure if its the right forum?

Plz help, any ideas appreciated.

 
If you write the web pages in jsp you can "include" files(txt, html, etc...).

For example, you could have a txt file for the heading, footer, main nav, sub nav, body and bring them in via a include statement
 
couls omeone give e an example of maybe having 2 text files loaded onto a page (text1.txt and text2.txt) with a horizontal rule in between, i kinda a noob to this whole web programming thing and to be honest have no idea where to start, an example should get me off the ground though.

Thanks ahead

------------------------------
------------------------------
 
may be a little sloppy but it works

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
%>
<HTML>
<HEAD>

</HEAD>
<BODY>
<%
function readtext1()
Const fsoForReading = 1

Dim objFSO
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile(&quot;C:\text1.txt&quot;, fsoForReading)

'Display the contents of the text file
Response.Write objTextStream.ReadAll

'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
end function

function readtext2()
Const fsoForReading = 1

Dim objFSO
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile(&quot;C:\text2.txt&quot;, fsoForReading)

'Display the contents of the text file
Response.Write objTextStream.ReadAll

'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
end function
%>

<%= readtext1()%><br><hr><br><%= readtext2()%>

</BODY>
</HTML>


Steve Bowman
steve.bowman@ultraex.com

 
Ah, i tried it but all i got was a blank page with a horizontal rule one line down?!?! not quite sure what is wrong with it becuase i seem to understand what is going on with the code! strange...

------------------------------
------------------------------
 
Could it be that im giving the file the wrong extension, i've used html, and htm and they haven't worked. I think that might be the problem

------------------------------
------------------------------
 
extension needs to be .asp and the server should be IIS

Steve Bowman
steve.bowman@ultraex.com

 
If you target audience is using IE (such as a corporate environment), the you can use the Tabular Data Control (TDC). TDC allows you to open CSV files from the same server as your HTML page and read the contents into a table or client side script. I've used it for simple search pages with limited amounts of information.

Check out this article:

Hope this helps.


Glen Appleton

VB.Net student.
 
That ASP script seems an awfully long way round to do it.

Much easier to use Server Side Includes (SSI). There's a couple of FAQs at faq253-3309 & faq253-2000 that tell you how to use them, but here's the example you asked for:
[tt]
<!--#include virtual=&quot;/text1.txt&quot; -->
<hr>
<!--#include virtual=&quot;/text2.txt&quot; -->
[/tt]
These directives are processed by the web server, so it won't matter what kind of browser the end user is using. This also means you won't see the includes working if you just look at the HTML file directly from your C: drive.

Your page will probably need to have a .shtml extension, by the way.


-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top