473,221 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

Use ASP to search text in Word docs on intranet

I use ASP to display links to Word documents on an intranet. Is there a way
in ASP to do text searches on the documents' contents? I want the results to
have the link to the Word document plus two or three lines from the document
that include the search terms.
Aug 17 '06 #1
5 3046
"Carstonio" <Ca*******@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.com...
I use ASP to display links to Word documents on an intranet. Is there a
way
in ASP to do text searches on the documents' contents? I want the results
to
have the link to the Word document plus two or three lines from the
document
that include the search terms.

The following script may get you started.

Option Explicit
Const cVBS = "Word_doc.vbs"
Const cDOC = "Word_doc.doc"
Dim objMSW
Set objMSW = CreateObject("Word.Application.8")
Dim objDOC
Set objDOC = objMSW.Documents.Open(cDOC)
Dim strDOC
strDOC = objDOC.Content
objDOC.Close False
objMSW.Application.Quit True
Set objDOC = Nothing
Set objMSW = Nothing
WScript.Echo strDOC

Since the above script is slow, I might suggest that
you have a process that uses the above to preprocess
each of your MS-Word documents and stores the
result in a database or text file then use that for your
searches.
Aug 17 '06 #2
"McKirahan" <Ne**@McKirahan.comwrote in message
news:ad******************************@comcast.com. ..
"Carstonio" <Ca*******@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.com...
I use ASP to display links to Word documents on an intranet. Is there a
way
in ASP to do text searches on the documents' contents? I want the
results
to
have the link to the Word document plus two or three lines from the
document
that include the search terms.


The following script may get you started.

Option Explicit
Const cVBS = "Word_doc.vbs"
Const cDOC = "Word_doc.doc"
Dim objMSW
Set objMSW = CreateObject("Word.Application.8")
Dim objDOC
Set objDOC = objMSW.Documents.Open(cDOC)
Dim strDOC
strDOC = objDOC.Content
objDOC.Close False
objMSW.Application.Quit True
Set objDOC = Nothing
Set objMSW = Nothing
WScript.Echo strDOC

Since the above script is slow, I might suggest that
you have a process that uses the above to preprocess
each of your MS-Word documents and stores the
result in a database or text file then use that for your
searches.
Here's a script that will process a list of MS-Word documents.

It will generate a Tab Separated Variable file with a header row of:
Document Line Text

Optionally, which can be opened up in MS-Excel for analysis
or review (via Data + Get External Data + Import Text File...).

Watch for word.wrap.

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "Document.vbs"
Const cTXT = "Document.txt"
Const cCSV = "Document.csv"
'*
'* Declare Variables
'*
Dim arrDOC
Dim intDOC
Dim strDOC
Dim intINS
Dim strOTF
Dim intTOT(1)
intTOT(0) = 0
intTOT(1) = 0
Dim strTOT
strTOT = "# Documents; ## Lines"
Dim arrTXT
Dim intTXT
Dim strTXT
'*
'* Declare Objects
'*
Dim objDOC
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objMSW
Set objMSW = CreateObject("Word.Application.8")
Dim objOTF
'*
'* Read list of databases
'*
Set objOTF = objFSO.OpenTextFile(cTXT,1)
strOTF = objOTF.ReadAll
Set objOTF = Nothing
'*
'* Documents, Lines
'*
Set objOTF = objFSO.OpenTextFile(cCSV,2,True)
objOTF.WriteLine("Document" & vbTab & "Line" & vbTab & "Text")
arrDOC = Split(strOTF,vbCrLf)
For intDOC = 0 To UBound(arrDOC)
strDOC = arrDOC(intDOC)
If InStr(LCase(strDOC),".doc") 0 Then
intINS = InStr(strDOC,":")
If intINS 0 Then strDOC = Mid(strDOC,intINS-1)
intTOT(0) = intTOT(0) + 1
objOTF.WriteLine(intTOT(0) & vbTab & "0" & vbTab & strDOC)
Set objDOC = objMSW.Documents.Open(strDOC)
strTXT = objDOC.Content
arrTXT = Split(strTXT,vbCr)
For intTXT = 0 To UBound(arrTXT)
If Trim(arrTXT(intTXT)) <"" Then
intTOT(1) = intTOT(1) + 1
objOTF.WriteLine(intTOT(0) & vbTab & intTOT(1) & vbTab &
arrTXT(intTXT))
End If
Next
objDOC.Close False
objMSW.Application.Quit True
Set objDOC = Nothing
End If
Next
Set objOTF = Nothing
'*
'* Destroy Objects
'*
Set objMSW = Nothing
Set objFSO = Nothing
'*
'* Finish
'*
strTOT = Replace(strTOT,"##",FormatNumber(intTOT(1),0))
strTOT = Replace(strTOT,"#",FormatNumber(intTOT(0),0))
MsgBox strTOT,vbInformation,cVBS
The input file ("Document.txt") can be generated via the MS-DOS
command "attrib". To identify all MS-Word documents on a drive:
run the following form a Command prompt:
attrib \*.doc /s Document.txt

Alternatively, you can just enter the filenames of the documents
that you're interested in into a text file one per line; for example:
C:\My Documents\Document1.doc
C:\My Documents\Document2.doc
An example of the output follows:
Document Line Text
1 0 C:\MYDOCU~1\Document1.doc
1 1 First line
1 2 Last line
2 0 C:\MYDOCU~1\Document2.doc
2 1 line number one
2 2 line number two
2 2 line number three

To reduce space, the document's filename is identified only once.
The filename is always on a "Line" of "0". Any questions?
Aug 17 '06 #3
"McKirahan" <Ne**@McKirahan.comwrote in message
news:c4******************************@comcast.com. ..

[snip]
If Trim(arrTXT(intTXT)) <"" Then
[snip]

Logic needs to be added before the above line to remove
unprintable characters. Let me know if you need it.
Aug 18 '06 #4
Thanks for your help. Your scripts appear to be written in VB, as opposed to
VBScript for an ASP-generated Web page. Our Intranet has at least 200 Word
files that are updated every month or so.

I like your idea of preprocessing. Is there a way to do that automatically
when the ASP search page loads, so the page creates a new text file if the
old file is a week old or missing?
Aug 18 '06 #5
"Carstonio" <Ca*******@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...
Thanks for your help. Your scripts appear to be written in VB, as opposed
to
VBScript for an ASP-generated Web page. Our Intranet has at least 200 Word
files that are updated every month or so.

I like your idea of preprocessing. Is there a way to do that automatically
when the ASP search page loads, so the page creates a new text file if the
old file is a week old or missing?
VBScript is the same whether it's in a .vbs or a .asp file.
There are are few minor differences; among them:
a) CretaeObject is Server.CreateObject
b) WScript.Echo (et.al). are not supported

My suggestion was that this be done offline using a .vbs
file rather than an .asp page though you could convert it.

It could be scheduled nightly so the file should be current.
Aug 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Benny Alexander | last post by:
Hi, We are developing a CMS in ASP and before we write the code for a complete site search script and Forum, we want to check if is there any good ones? Kindly please let us know. Thanks in...
2
by: Dhanraj K.S | last post by:
Hi All, Is there any Site search application which is extremely powerful. It would be a great help if some one can suggest! Thanks in advance,
3
by: Carol | last post by:
What's the best way to do a site search of my site? I am using asp and access heavily on a regular ISP google? Or write a bunch of queries? what else is there?
2
by: Erik Ronne | last post by:
Hello Gurus I have an intranet web page with links to all kinds of Microsoft Word document that we use at my work, so my co-works can go to the web page when they need a special document....
3
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been...
83
by: D. Dante Lorenso | last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org is extremely SLOW. Considering this is a website for a database and databases are supposed to be good for indexing content, I'd...
3
by: Michael | last post by:
Hi, I have not implimented a search feature yet for a web site yet and wanted to get some advice. Most of the search tips I have seen so far only deal with searching html files or other web files....
22
by: liya.tansky | last post by:
Hello, I'm developing an intranet (win XP, .NET 2, Visual Studio 2005, Microsoft.Office.Interop.Word.dll in references) and needed to implement find-replace in word doc before sending letter and...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.