1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Writing meta-tag values in the HTML code

Discussion in 'C#' started by shlomot, Sep 4, 2006.

  1. #1
    I would like to keep a single header file for all 15K pages. However, the <h1>Title</h1> in the header should be personalized according with the individual pages.

    I wonder if it's possible to read values from specific tags in the <head></head> section of each page and write it as HTML in the document’s body?

    I'm novice in ASP coding so please include some mercy with your help :)
     
    shlomot, Sep 4, 2006 IP
  2. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Yes it possible

    step 1) Load your file for read
    Step 2) Find <head> starting posion and end posision </head> using substring
    step 3) now open your file in update mode and add one line <h1>var1</h1>
    step 4)update file

    tack back up file before do
     
    shaileshk, Sep 4, 2006 IP
  3. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Sub WriteToFile(strFilePath, strData, iLineNumber)
       Dim objFSO, objFile, arrLines
       Dim strAllFile, x
       Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
       strAllFile=""
       If objFSO.FileExists(strFilePath) Then
          Set objFile=objFSO.OpenTextFile(strFilePath)
          If Not(objFile.AtEndOfStream) Then
             strAllFile = objFile.ReadAll
          End If
          objFile.Close
       End If
       arrLines = Split(strAllFile, VBCrLf)
       Set objFile=objFSO.CreateTextFile(strFilePath)
       For x=0 To UBound(arrLines)
          If (iLineNumber-1)=x Then objFile.WriteLine(strData)
          objFile.WriteLine(arrLines(x))
       Next
       If iLineNumber>=UBound(arrLines) Then objFile.WriteLine(strData)
       objFile.Close
       Set objFile=Nothing
       Set objFSO=Nothing
    End Sub 
    
    'usage:
    Call WriteToFile(Server.MapPath("log.txt"), Request.ServerVariables("REMOTE_ADDR"), 5)
    Code (markup):
     
    shaileshk, Sep 4, 2006 IP
  4. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    use a master page in asp.net and then in the page_load of your content page add page.title = "My page" . You can also add any metatags using much the same method.
     
    Free Born John, Sep 4, 2006 IP
  5. shlomot

    shlomot Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you so much for replying, John.

    As I promissed in my original post - I've absolutely no clue as to what you've just said.

    Can you please repeat it in an ASP for Dummies jargon?
     
    shlomot, Sep 4, 2006 IP
  6. rooneydavid

    rooneydavid Guest

    Messages:
    67
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    On my site www.new-york-hotels.net I just a template system, where I open a static html file and read it, do a search and replace on place holders and then write it to the new asp page. My template page can be seen here: www.new-york-hotels.net/template/template.html. Alot of the code to do this and other functions I cant show but below is a simple version.

    First you need a html template called "template.html"

    Then you need an asp file
    <%
    	' Here we open the HTML File
    	Set myFileSystem = Server.CreateObject("Scripting.FileSystemObject")
    	Set myHtmlFile = myFileSystem.GetFile(server.MapPath("template.html"))' (server.MapPath("template.html"))
    	Set objTextStream = myHtmlFile.OpenAsTextStream(1,0)
    	
    	' Here we read all of it
    	strHtmlPage = objTextStream.ReadAll	
    
    	' Close the file system connection
    	Set myFileSystem = Nothing
    	Set myHtmlFile = Nothing
    	Set objTextStream = Nothing
    
    	' Here we do a search and replace.
    	strHtmlPage = Replace(strHtmlPage, "<h1></h1>", "<h1>PAGE TITLE</h1>")
    	
    	' Split the page into two
    	aryPageTemplate = Split(strHtmlPage,"###Content###",-1)
    	
    	' Now we write the code into the new asp file
    	Response.Write(aryPageTemplate(0))
    %>
    BLAH BLAH
    <% Response.Write(aryPageTemplate(1)) %>
    Code (markup):
    What that will do is search for empty h1 tags and replace it with the PAGE TITLE then split the page at the ###Content### text and write the first and second halfs around the blah blah text.
     
    rooneydavid, Sep 4, 2006 IP