7/26/00
 Quick Links :
home| forum | whats new | advertise | contact us




Overview
Access Database
Indexing using HTTP protocol
Indexing using FilySystemObject
Deleting URLs from Database
HTML Search Engine Form
Searching Records in the Database
Include File
Conclusion

WantJava.com


Please support our sponsors

Creating 'addtodb_fso.asp' page

Create a new blank ASP page and name it 'addtodb_fso.asp'. Then copy paste the following code into it :

   <!--#include file="editme.asp"-->
   <html>
   <head>
      <style>
         body { font-family : Verdana; font-size : 8pt; }
      </style>
   </head>
   <body>

 <%    On Error Resume Next
   Dim geturl, title, description, keywords, strURL, strDB, con, results
   Dim fso, file, path

      ' URL
      If Trim(Request.QueryString("base_url")) <> "" And _
                  Request.QueryString("look_for") <> "" Then
      strURL = Request.QueryString("base_url") & Request.QueryString("look_for")
      path = Server.MapPath(Request.QueryString("look_for"))

      ' FileSystemObject
      Set fso = CreateObject("Scripting.FileSystemObject")

      ' File Object
      Set file = fso.OpenTextFile(path, 1, False)

      ' Reading the contents of the File into strFileContents
      strFileContents = file.ReadAll

      ' Keywords
      key1 = InStr(1, strFileContents, "<meta name=""keywords"" content=""", 1)
      key1 = key1 + Len("<meta name=""keywords"" content=""")
      key2 = InStr(key1, strFileContents, """>", 1)

      keywords = "," & Trim(Mid(strFileContents, key1, (key2 - key1))) & ","
      keywords = Replace (keywords, "'", " ")

      ' Description
      desc1 = InStr(1, strFileContents, "<meta name=""description"" content=""", 1)
      desc1 = desc1 + Len("<meta name=""description"" content=""")
      desc2 = InStr(desc1, strFileContents, """>", 1)

      description = Trim(Mid(strFileContents, desc1, (desc2 - desc1)))
      description = Replace (description, "'", " ")

      ' Title
      tit1 = InStr(1, lcase(strFileContents), "<title>", 1)
      tit1 = tit1 + Len("<title>")
      tit2 = InStr(tit1, strFileContents, "</title>", 1)

      title = Trim(Mid(strFileContents, tit1, (tit2 - tit1)))
      title = Replace (title, "'", " ")

      ' Our Connection Object
      Set con = CreateObject("ADODB.Connection")
      con.Open strDB
      Set results = con.Execute("select title, description, keywords _
                  from all_pages where url = '" & strURL & "'")

      ' If the returning recordset is empty the add the URL with accompanying
      ' info to the database
      If results.EOF Then
         con.Execute("insert into all_pages (title, description, keywords, url, _
                  mydate) values ('" & title & "', '" & description & "', '" & _
                  keywords & "', '" & strURL & "', '" & date & "')")
         Set rs = con.Execute("select count(url) as total_count from all_pages")
         cnt = rs("total_count")
         Set rs = Nothing
         Response.Write "<b>New account successfully created for " & strURL & " _
                  .</b>" & vbcrlf
         Response.Write "<br>"
         Response.Write "Total Pages Indexed : " & cnt & vbcrlf
      Else
      ' But if the returning recordset is not empty i.e. we have already added _
      ' title, desc, keywords etc into it then update that information with the _
      ' new one.
         con.Execute("update all_pages set title = '" & title & "', description = _
                  '" & description & "', keywords = '" & keywords & "', mydate = #" _
                  & date & "# where url = '" & strURL & "'")
         Response.Write "<b>Account updated successfully.</b>"
      End If

      ' Done. Now release Objects
      Set results = Nothing
      con.Close
      Set con = Nothing

      Else
      Response.Write "Please enter the base URL and File path correctly. Thanks."
      End If
 %>
   </body></html>

Almost similar to 'addtodb.asp' with only difference being of the following code :

      ' URL
      If Trim(Request.QueryString("base_url")) <> "" And _
                  Request.QueryString("look_for") <> "" Then
      strURL = Request.QueryString("base_url") & Request.QueryString("look_for")
      path = Server.MapPath(Request.QueryString("look_for"))

      ' FileSystemObject
      Set fso = CreateObject("Scripting.FileSystemObject")

      ' File Object
      Set file = fso.OpenTextFile(path, 1, False)

      ' Reading the contents of the File into strFileContents
      strFileContents = file.ReadAll

On the next page we continue with the exploration of 'addtodb_fso.asp' page.



Next -> 




© 1999-2000 Faisal Khan, All rights reserved