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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing page title 1

Status
Not open for further replies.

benrob82

Programmer
Jul 28, 2005
116
GB
Hi all,

i have this code in the header of my page to read the first line of my html containing <h2> and then pull this out to be my page title but it doesn't seem to be working can anyone see why?

<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\Temp\page1.asp")
Set objTextStream = objFile.OpenAsTextStream(ForReading)

Do Until objTextStream.AtEndOfStream
strLine = LCase(objTextStream.ReadLine())

If InStr(strLine, "<h2>") Then
Exit Do
End If
Loop

Set objTextStream = Nothing
Set objFile = Nothing
Set objFSO = Nothing

strLine = Replace(strLine, "<h2>", "")
strLine = Replace(strLine, "</h2>", "")
%>


thanks
 
if I change the path to

Code:
Set objFile = objFSO.GetFile(Server.MapPath("/content/80000/templates/connect_top.asp"))

it produces the following error which at least shows its getting to the correct file

Code:
Microsoft VBScript runtime error '800a0005' 

Invalid procedure call or argument 

/content/80000/templates/connect_top.asp, line 9
 
Set objTextStream = objFile.OpenAsTextStream(ForReading)
 
ForReading is a VB constant. If you dont have the msado15.dll included then you will either need to include that file or replace ForReading with its numeric equivalent, 1

For now just use:
Code:
Set objTextStream = objFile.OpenAsTextStream(1)

Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
Hi sorry for the late reply,

it inserted the following into the page title
Code:
If InStr(strLine, "") Then

without the <h2> tag

Code:
If InStr(strLine, "<h2>") Then
 
here you go, thanks for all your help on this

Code:
<!-- #include virtual="/includes/functions.inc" -->
<!-- #include virtual="/home/site/constants.inc" -->
<!-- #include virtual="/includes/checklogin.inc" -->
<!-- #include virtual="/app/includes/functions.inc" -->
<!-- #include virtual="/app/includes/constants.inc" -->
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(Server.MapPath("/content/80000/templates/connect_top.asp"))
Set objTextStream = objFile.OpenAsTextStream(1)

Do Until objTextStream.AtEndOfStream
  strLine = LCase(objTextStream.ReadLine())

  If InStr(strLine, "<h2>") Then
    Exit Do
  End If
Loop

Set objTextStream = Nothing
Set objFile = Nothing
Set objFSO = Nothing

strLine = Replace(strLine, "<h2>", "")
strLine = Replace(strLine, "</h2>", "")
%>
<%

	sub main	
				
	end sub	
%>
<!-- #include virtual="/includes/main.inc" -->
<%
	if left(pageurl,len(MEMBERS_CONTENT_DIRECTORY)) = MEMBERS_CONTENT_DIRECTORY then		
		%><!-- #include virtual="/app/connect/members/checklogin.inc" --><%	
	elseif left(pageurl,len(STUDENT_CONTENT_DIRECTORY)) = STUDENT_CONTENT_DIRECTORY then
		%><!-- #include virtual="/app/connect/graduates/checklogin.inc" --><%	
	end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link REL="STYLESHEET" HREF="/home/site/80000/styles/connect.css" TYPE="text/css">
<title><%=strLine%></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<!-- #include virtual="/app/includes/mainsitetabletop.inc" -->
<!---headerBar--->
<!-- #include virtual="/app/includes/headerbar.inc" -->
<!---/headerBar--->

<!--- mainBodyTable--->
  <table border="0" cellpadding="0" cellspacing="0" width="715">
    <tr> 
	  <!---navBar--->
      <!-- #include virtual="/app/includes/navbar.inc" -->
      <!---/navBar--->
      <!---content--->      
      <td valign="top"> 
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
	  <tr>
	  <td colspan="3"><img src="/webimages/spacer.gif" alt="" name="" width="10" height="10" border="0"></td></tr>	  
	  <tr>
	  <td><img src="/webimages/spacer.gif" alt="" name="undefined_4" width="10" height="1" border="0"></td>
	  <td width="100%">
 
you are reading a file called connect_top. This file doesnt have a correct [red]<h2>your page heading</h2>[/red] line at the top does it?

The code you have is expecting a line like [red]<h2>your page heading</h2>[/red] somewhere on the page (preferably near the top).

Point the code to a page with a proper heading in it


Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
this is the include file, its called connect_top and is included in all pages with each page then has a <h2> heading at the top. As the include file is included at the top of each page it should be able to read the code within that page.

Is this correct?
 
sorry I know i've just found that out, it works if it point it directly at the actual page

Code:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(Server.MapPath("/content/80000/connect/home/home.asp"))

although it does leave a <br> on the end, but it works now I just need to be able to point this at each page dynamically.
 
if it still has a <br> then you can remove it here
Code:
strLine = Replace(strLine, "<h2>", "")
strLine = Replace(strLine, "</h2>", "")
[red]strLine = Replace(strLine, "<br>", "")[/red]
As for reading the page dynamically, you should be able to make use of ServerVariables as we mentioned before.

Try adding this line after the above code to check that the correct page is getting returned:
Code:
Response.Write Request.ServerVariables("PATH_TRANSLATED")

Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
yeah its displaying the page url at the top of the page before the actual page is displayed but its doing it correctly, the getfile requires an input string and adding the request server variables isn't working.
 
thats right but I got it working, thanks for all your help, got there in the end

Code:
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(Server.MapPath(Request.ServerVariables("URL")))
Set objTextStream = objFile.OpenAsTextStream(1)

Do Until objTextStream.AtEndOfStream
  strLine = LCase(objTextStream.ReadLine())

  If InStr(strLine, "<h2>") Then
    Exit Do
  End If
Loop

Set objTextStream = Nothing
Set objFile = Nothing
Set objFSO = Nothing

strLine = Replace(strLine, "<h2>", "")
strLine = Replace(strLine, "</h2>", "")
strLine = Replace(strLine, "<br>", "")
%>

I replaced the path translated as it wasn't a vaild input type with

Code:
Set objFile = objFSO.GetFile(Server.MapPath(Request.ServerVariables("URL")))

which seemed to solve the problem, its just a case of tidying up the random tags, thanks man you've been a legend
 
Great...it worked in the end for you...BTW how many threads did you open on this topic?? [bigsmile]

-DNG
 
Hi,

there is a tag on the same line as the H2 and I can't filter it out using the

strLine = Replace(strLine, "<!---@ORCHIDNET~CONTENT@--->", "")

any ideas why this is?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top