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
 
code looks good to me...why is it not working...do you get any errors...

-DNG
 
there is a problem with this part of code

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

 
but what is the problem?? any specific error??

yes i remember you had a similar thread in the past...put all this code in a .asp file and include in your other files...

-DNG
 
i removed it from an inc file and just added it to the header.asp file and the error still was produced
 
i repeat...please tell us what is the error that you are getting...

-DNG
 
Description Expecting string input
Page /content/80000/templates/top.asp
Line 8
More Info The function expects a string as input.

this is the error which relates to the
Set objFile = objFSO.GetFile("content/80000/about/about.asp")

but i need this to read the file it is currently in rather than a specific location
 
this path: "content/80000/about/about.asp" does not seem right to me...

try something like this:
myfile=Server.MapPath("/about.asp")
'check to see if the path is correct..
'response.write myfile
Set objFile = objFSO.GetFile(myfile)

-DNG
 
Script : /content/80000/templates/top.asp
Number :
Description : Object doesn't support this property or method: 'objFSO.GetFilemyfile'
Code :
Line : 8
Extra Info :


the following error occured
 
objFSO.[red]GetFilemyfile[/red]

i never asked you to use that...

i said objFSO.GetFile(myfile)

-DNG
 
I cant get this to work at all, is it possible as the header is going to go into all of the relevent pages to just read within the file and pull out the first <h2> it comes to??
 
can you post your complete code that you tried. and also post the error you are getting...

-DNG
 
This is the header information that goes into the top of all of my pages.

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(Request.ServerVariables(PATH_TRANSLATED))
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>", "")
%>
<%

	sub main	
				
	end sub	
%>
<!-- #include virtual="/includes/main.inc" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<link REL="STYLESHEET" HREF="/home/site/80000/styles/style.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" summary="Top Table Format" cellpadding="0" cellspacing="0" width="715">
    <tr> 
	  <!--navBar-->
      <!-- #include virtual="/app/includes/navbar.inc" -->
      <!--/navBar-->
      <!--content-->      
      <td valign="top"> 
        <table width="100%" summary="Top Sub Section" 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%">
 
change this:

Set objFile = objFSO.GetFile(Request.ServerVariables(PATH_TRANSLATED))

to this:

Set objFile = objFSO.GetFile(Request.ServerVariables(PATH_INFO))

-DNG
 
the follwing error occured

Code:
Expecting string input 

/content/80000/templates/connect_top.asp, line 8 

The function expects a string as input.
 
ok try this as a test case:

Set objFile = objFSO.GetFile(Server.MapPath("connect_top.asp"))

-DNG
 
the error is below

Code:
File not found 

/content/80000/templates/connect_top.asp, line 8
 
can you what is the exact path of your file connect_top.asp

and also tell the path of this include file in which you are using this code...

-DNG
 
the include file is located in

/content/80000/templates/connect_top.asp

and the file the code appears in is

/content/80000/connect/home/home.asp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top