Searching and Server.MapPath

Results 1 to 3 of 3

Thread: Searching and Server.MapPath

  1. #1
    Join Date
    Dec 1969

    Default Searching and Server.MapPath

    Hi im using this script from the 4guysfromrolla site. I trying to come up with a search that will search words or a string from a directory of htm files from another location.<BR><BR>So for example the ASP pages im using to display the results are on one website. And the actual files i need searching are at another. Is this possible without too much hassle?<BR><BR>Is there anything I can do to the Server.MapPath for it to use an url as opposed to a direct path.?<BR><BR><BR>&#060;HTML&#062;&#060;BODY&#062; <BR>&#060;B&#062;Search Results for &#060;%=Request("SearchText")%&#062;&#060;/B&#062;<BR><BR><BR>&#060;%<BR>Const fsoForReading = 1<BR><BR>Dim strSearchText<BR>strSearchText = Request("SearchText")<BR><BR>&#039;Now, we want to search all of the files<BR>Dim objFSO<BR>Set objFSO = Server.CreateObject("Scripting.FileSystemObject")< BR><BR><BR>Dim objFolder<BR>Set objFolder = objFSO.GetFolder(Server.MapPath(""))<BR><BR>Dim objFile, objTextStream, strFileContents, bolFileFound<BR>bolFileFound = False<BR><BR>For Each objFile in objFolder.Files<BR> If Response.IsClientConnected then<BR> Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)<BR ><BR> strFileContents = objTextStream.ReadAll<BR><BR> If InStr(1,strFileContents,strSearchText,1) then<BR> Response.Write "&#060;LI&#062;&#060;A HREF=""/" & objFile.Name & _<BR> """&#062;" & objFile.Name & "&#060;/A&#062;<BR>"<BR><BR> bolFileFound = True<BR> End If<BR><BR> objTextStream.Close<BR> End If<BR>Next<BR><BR>if Not bolFileFound then Response.Write "No matches found..."<BR><BR>Set objTextStream = Nothing<BR>Set objFolder = Nothing<BR>Set objFSO = Nothing<BR>%&#062;<BR><BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR> <BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default That's kind of like...

    ...trying to use a dictionary in the living room when you&#039;re in the bedroom.<BR><BR>No. You can&#039;t do it. Period.<BR><BR>Server.MapPath *ONLY* applies to files in the current virtual directory. Period. Which means on the same machine (or, in some cases, machines on the same LAN).<BR><BR>As an ASP user, you should be among the first to realize that a URL is *NOT* necessarily a file, at all. It&#039;s quite possible that a given site might have no "files" as we know them at all; it simply delivers up HTML pages based entirely on dynamic content.<BR><BR>*CAN* you get info from URLs? Sure. Using (for example) the MSXML2.ServerXMLHTTP component. <BR><BR>Would I recommend doing that, in order to do a real-time search? No way. You have no control over that other system, so for all you know it might take it 5 minutes to return each requested page.<BR><BR>If you need this kind of capability, consider using a commercial search service, such as Google.<BR><BR><BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default No.

    You can&#039;t modify this script directly to use a URL.<BR><BR>There are, however, other methods to create a remote site search. would be a good place to start, I&#039;d think.<BR><BR>Craig.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts