Knowledgebase Home Page  >  SearchUnit  >  Version 2 Articles
Search the Knowledge Base
How can I index files on my local filesystem? (VB.NET)
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=100&catId=66

Options

Print this page
Email this to a friend
Search Lite for ASP.NET is designed primarily to be a web-site indexer, and includes a web-site spider/crawler that visits web-sites from a users perspective.  This product can also search documents on local drives using the file-system.  To do this, we need to programmatically add documents to the index, and then build the index as usual.
 
1) You will scan directories to identify files that should be indexed

2) You'll programmatically add these files to the index

3) You'll build the index programmatically and then you can run searches (programmatically or from the web control)

 
In the following code we reference our demo project "Programmatic_VB.NET" which is installed with the main product, this gives you the simple framework to run builds and searches within.
 
 
 
 

Now go through 1, 2 and 3 from above:
 


1. Scanning directories for documents to add, in this code we will search for all PDF and Word docs.

i) add a button to the form in the demo and attach an event handler for it's click

ii) add this method

Public Sub FindDocs(ByVal theFoundItems As ArrayList, ByVal theRoot As String)

Dim theDirectories() As String = System.IO.Directory.GetDirectories(theRoot)
For Each theDirectory As String In theDirectories
FindDocs(theFoundItems, theDirectory)
Next

' Now scan the files in the current directory for any that match...
Dim theFiles() As String = System.IO.Directory.GetFiles(theRoot)

For Each theFile As String In theFiles
If theFile.ToLower().IndexOf(".pdf") > -1 Or theFile.ToLower().IndexOf(".doc") > -1 Then    'PDF & DOC FILE FILTER
theFoundItems.Add(theFile)
End If
Next

End Sub

 

and use it from your button click
 


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim docs As New ArrayList
FindDocs(docs, "C:\Inetpub\wwwroot")
'docs now has paths to all Doc and PDF files under wwwroot (careful, this method can take a long time)

End Sub
 
 
 


2. Add the docs to the index by modifying the Button1_Click to include

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim docs As New ArrayList
FindDocs(docs, "C:\Inetpub\wwwroot")
'docs now has paths to all Doc and PDF files under wwwroot (careful, this method can take a long time)
'add the docs to the index
Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Try
indexer.Open()
Dim doc As String
For Each doc In docs
indexer.AddDocument(New Keyoti.SearchEngine.Documents.Document(New Keyoti.SearchEngine.DataAccess.DocumentRecord(New Uri(doc))))
Next
indexer.Close()
Catch ex As Exception
MessageBox.Show(("An error occurred: " + ex.Message))
End Try
MessageBox.Show("Recursive find ended")

'call UpdateKnownDocs() to refresh list of docs in index
UpdateKnownDocs()
End Sub
 
 
 
 
 


3. Now the index can be built, in the demo this is already taken care of with the Build Index button, it just calls

Sub RunBuild()
builderFinished = False
Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Try
indexer.Open()
indexer.Build()
indexer.Close()
Catch e As Exception
MessageBox.Show(("An error occurred: " + e.Message))
End Try

builderFinished = True
Me.stopBuildBT.Enabled = False
Me.indexBT.Enabled = True
MessageBox.Show("Build ended")
End Sub
 
 


That will add all the docs/pdfs it can find to the index, once you've built the index you can run searches programmatically (see demo) or using the SearchResult control by pointing it's IndexDirectory property at the directory where you built this index.


Caveats;
1. recursively searching an entire hard drive can take time, so limit paths as much as possible
 
 
 
 
Complete modified code from demo project (just replace Form1 in the demo with this):
 

Public Class Form1

Inherits System.Windows.Forms.Form

 

Dim spider As New Keyoti.SearchEngine.Index.WebSiteSpider

Dim indexer As New Keyoti.SearchEngine.Index.DocumentIndex

Dim indexDir As String = "..\IndexDirectory"

Dim crawlerFinished, builderFinished As Boolean

 

 

'-TOOL METHODS

#Region "Crawl"

Private Sub crawlBT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles crawlBT.Click

'start crawl the thread

Dim crawlThread As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf RunCrawl))

crawlThread.Start()

'start the progress thread

Dim crawlProgressThread As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf RunCrawlUpdater))

crawlProgressThread.Start()

Me.stopCrawlBT.Enabled = True

Me.crawlBT.Enabled = False

End Sub 'crawlBT_Click

 

 

Sub RunCrawl()

crawlerFinished = False

Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Try

spider.Open()

spider.Crawl(New ArrayList(New String() {Me.crawlURLTB.Text}))

spider.Close()

Catch e As Exception

MessageBox.Show(("An error occurred: " + e.Message))

End Try

crawlerFinished = True

Me.stopCrawlBT.Enabled = False

Me.crawlBT.Enabled = True

MessageBox.Show("Crawl ended")

UpdateKnownDocs()

End Sub 'RunCrawl

 

'updates the UI with crawl progress

Sub RunCrawlUpdater()

While Not crawlerFinished

System.Threading.Thread.Sleep(100)

Me.crawlProgress.Text = spider.NewLinkNo & " new of " & spider.ProcessedLinkNo & " links"

End While

End Sub 'RunCrawlUpdater

 

'stops the crawl

Private Sub stopCrawlBT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles stopCrawlBT.Click

Keyoti.SearchEngine.Index.WebSiteSpider.cancelCrawl = True

End Sub 'stopCrawlBT_Click

#End Region

#Region "Delete"

Private Sub deleteIndexBT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles deleteIndexBT.Click

Me.deleteIndexBT.Enabled = False

Me.deleteIndexBT.Text = "Deleting..."

Dim delThread As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf RunDelete))

delThread.Start()

End Sub 'deleteIndexBT_Click

 

 

 

Sub RunDelete()

Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Dim ind As New Keyoti.SearchEngine.Index.DocumentIndex

ind.Open()

Dim docs As ArrayList = ind.GetIndexedDocuments()

Dim doc As Keyoti.SearchEngine.Documents.Document

For Each doc In docs

ind.RemoveDocument(doc.URI.ToString())

Next doc

ind.Close()

Me.deleteIndexBT.Enabled = True

Me.deleteIndexBT.Text = "Delete"

MessageBox.Show("Index deleted")

UpdateKnownDocs()

End Sub 'RunDelete

#End Region

#Region "Build Index"

Private Sub indexBT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles indexBT.Click

'start build the thread

Dim buildThread As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf RunBuild))

buildThread.Start()

'start the progress thread

Dim buildProgressThread As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf RunBuildUpdater))

buildProgressThread.Start()

Me.stopBuildBT.Enabled = True

Me.indexBT.Enabled = False

End Sub 'indexBT_Click

 

 

Sub RunBuild()

builderFinished = False

Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Try

indexer.Open()

indexer.Build()

indexer.Close()

Catch e As Exception

MessageBox.Show(("An error occurred: " + e.Message))

End Try

builderFinished = True

Me.stopBuildBT.Enabled = False

Me.indexBT.Enabled = True

MessageBox.Show("Build ended")

End Sub 'RunBuild

 

'updates the UI with build progress

Sub RunBuildUpdater()

While Not builderFinished

System.Threading.Thread.Sleep(100)

If indexer.Progress < 100 Then

buildProgress.Text = indexer.Progress & "% built"

Else

buildProgress.Text = indexer.OccurrenceCount & " indexed - saving..."

End If

End While

buildProgress.Text = "Finished"

End Sub 'RunBuildUpdater

 

Private Sub stopBuildBT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles stopBuildBT.Click

Keyoti.SearchEngine.Index.DocumentIndex.cancelBuild = True

End Sub 'stopBuildBT_Click

#End Region

#Region "Search"

Private Sub searchBT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchBT.Click

Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Try

Dim resultsOutput As String = ""

Dim sa As New Keyoti.SearchEngine.Search.SearchAgent

sa.QueryString = Me.queryTB.Text

sa.LicenseKey = Me.licenseTB.Text

'get first 50 results only

Dim results As Keyoti.SearchEngine.Search.SearchResult = sa.Search(1, 50)

Dim item As Keyoti.SearchEngine.Search.ResultItem

For Each item In results

resultsOutput += item.URIString + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf

Next item

If results.Count = 0 Then

resultsOutput = "No results found"

End If

Me.resultsTB.Text = resultsOutput

Catch ex As Exception

MessageBox.Show(("An error occurred: " + ex.Message))

End Try

End Sub 'searchBT_Click

#End Region

#Region "E.t.c."

Private Sub checkBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkBox1.CheckedChanged

Keyoti.SearchEngine.Configuration.logging = Me.checkBox1.Checked

End Sub 'checkBox1_CheckedChanged

 

Sub UpdateKnownDocs()

Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Try

Dim output As String = ""

indexer.Open()

Dim docs As ArrayList = indexer.GetIndexedDocuments()

Dim doc As Keyoti.SearchEngine.Documents.Document

For Each doc In docs

output += doc.URI.ToString() + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf

Next doc

indexer.Close()

If docs.Count = 0 Then

output = "No documents in index"

End If

Me.knownDocsTB.Text = output

Catch e As Exception

MessageBox.Show(("An error occurred: " + e.Message))

End Try

End Sub 'UpdateKnownDocs

#End Region

 

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents checkBox1 As System.Windows.Forms.CheckBox

Friend WithEvents deleteIndexBT As System.Windows.Forms.Button

Friend WithEvents groupBox3 As System.Windows.Forms.GroupBox

Friend WithEvents label3 As System.Windows.Forms.Label

Friend WithEvents licenseTB As System.Windows.Forms.TextBox

Friend WithEvents resultsTB As System.Windows.Forms.TextBox

Friend WithEvents label2 As System.Windows.Forms.Label

Friend WithEvents queryTB As System.Windows.Forms.TextBox

Friend WithEvents searchBT As System.Windows.Forms.Button

Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox

Friend WithEvents stopBuildBT As System.Windows.Forms.Button

Friend WithEvents buildProgress As System.Windows.Forms.Label

Friend WithEvents indexBT As System.Windows.Forms.Button

Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox

Friend WithEvents label4 As System.Windows.Forms.Label

Friend WithEvents stopCrawlBT As System.Windows.Forms.Button

Friend WithEvents crawlProgress As System.Windows.Forms.Label

Friend WithEvents crawlBT As System.Windows.Forms.Button

Friend WithEvents crawlURLTB As System.Windows.Forms.TextBox

Friend WithEvents knownDocsTB As System.Windows.Forms.TextBox

Friend WithEvents label1 As System.Windows.Forms.Label

Friend WithEvents Button1 As System.Windows.Forms.Button

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.checkBox1 = New System.Windows.Forms.CheckBox

Me.deleteIndexBT = New System.Windows.Forms.Button

Me.groupBox3 = New System.Windows.Forms.GroupBox

Me.label3 = New System.Windows.Forms.Label

Me.licenseTB = New System.Windows.Forms.TextBox

Me.resultsTB = New System.Windows.Forms.TextBox

Me.label2 = New System.Windows.Forms.Label

Me.queryTB = New System.Windows.Forms.TextBox

Me.searchBT = New System.Windows.Forms.Button

Me.groupBox2 = New System.Windows.Forms.GroupBox

Me.stopBuildBT = New System.Windows.Forms.Button

Me.buildProgress = New System.Windows.Forms.Label

Me.indexBT = New System.Windows.Forms.Button

Me.groupBox1 = New System.Windows.Forms.GroupBox

Me.label4 = New System.Windows.Forms.Label

Me.stopCrawlBT = New System.Windows.Forms.Button

Me.crawlProgress = New System.Windows.Forms.Label

Me.crawlBT = New System.Windows.Forms.Button

Me.crawlURLTB = New System.Windows.Forms.TextBox

Me.knownDocsTB = New System.Windows.Forms.TextBox

Me.label1 = New System.Windows.Forms.Label

Me.Button1 = New System.Windows.Forms.Button

Me.groupBox3.SuspendLayout()

Me.groupBox2.SuspendLayout()

Me.groupBox1.SuspendLayout()

Me.SuspendLayout()

'

'checkBox1

'

Me.checkBox1.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.checkBox1.Location = New System.Drawing.Point(112, 40)

Me.checkBox1.Name = "checkBox1"

Me.checkBox1.TabIndex = 12

Me.checkBox1.Text = "Logging"

'

'deleteIndexBT

'

Me.deleteIndexBT.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.deleteIndexBT.Location = New System.Drawing.Point(16, 40)

Me.deleteIndexBT.Name = "deleteIndexBT"

Me.deleteIndexBT.Size = New System.Drawing.Size(80, 23)

Me.deleteIndexBT.TabIndex = 11

Me.deleteIndexBT.Text = "Delete index"

'

'groupBox3

'

Me.groupBox3.Controls.Add(Me.label3)

Me.groupBox3.Controls.Add(Me.licenseTB)

Me.groupBox3.Controls.Add(Me.resultsTB)

Me.groupBox3.Controls.Add(Me.label2)

Me.groupBox3.Controls.Add(Me.queryTB)

Me.groupBox3.Controls.Add(Me.searchBT)

Me.groupBox3.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.groupBox3.Location = New System.Drawing.Point(424, 72)

Me.groupBox3.Name = "groupBox3"

Me.groupBox3.Size = New System.Drawing.Size(496, 472)

Me.groupBox3.TabIndex = 10

Me.groupBox3.TabStop = False

Me.groupBox3.Text = "Search"

'

'label3

'

Me.label3.Location = New System.Drawing.Point(16, 64)

Me.label3.Name = "label3"

Me.label3.Size = New System.Drawing.Size(72, 23)

Me.label3.TabIndex = 5

Me.label3.Text = "License key:"

'

'licenseTB

'

Me.licenseTB.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

Me.licenseTB.Location = New System.Drawing.Point(104, 64)

Me.licenseTB.Name = "licenseTB"

Me.licenseTB.Size = New System.Drawing.Size(376, 18)

Me.licenseTB.TabIndex = 4

Me.licenseTB.Text = "5550655C6258645D665768675F5864364E4F3E3C363C3E393F3B414041484048494D4B1"

'

'resultsTB

'

Me.resultsTB.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

Me.resultsTB.Location = New System.Drawing.Point(16, 104)

Me.resultsTB.Multiline = True

Me.resultsTB.Name = "resultsTB"

Me.resultsTB.ScrollBars = System.Windows.Forms.ScrollBars.Vertical

Me.resultsTB.Size = New System.Drawing.Size(472, 360)

Me.resultsTB.TabIndex = 3

Me.resultsTB.Text = "Results:"

'

'label2

'

Me.label2.Location = New System.Drawing.Point(16, 24)

Me.label2.Name = "label2"

Me.label2.Size = New System.Drawing.Size(80, 23)

Me.label2.TabIndex = 2

Me.label2.Text = "Search query:"

'

'queryTB

'

Me.queryTB.Location = New System.Drawing.Point(104, 24)

Me.queryTB.Name = "queryTB"

Me.queryTB.Size = New System.Drawing.Size(296, 20)

Me.queryTB.TabIndex = 1

Me.queryTB.Text = ""

'

'searchBT

'

Me.searchBT.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.searchBT.Location = New System.Drawing.Point(408, 24)

Me.searchBT.Name = "searchBT"

Me.searchBT.Size = New System.Drawing.Size(80, 23)

Me.searchBT.TabIndex = 0

Me.searchBT.Text = "Search"

'

'groupBox2

'

Me.groupBox2.Controls.Add(Me.stopBuildBT)

Me.groupBox2.Controls.Add(Me.buildProgress)

Me.groupBox2.Controls.Add(Me.indexBT)

Me.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.groupBox2.Location = New System.Drawing.Point(8, 464)

Me.groupBox2.Name = "groupBox2"

Me.groupBox2.Size = New System.Drawing.Size(408, 80)

Me.groupBox2.TabIndex = 9

Me.groupBox2.TabStop = False

Me.groupBox2.Text = "Index"

'

'stopBuildBT

'

Me.stopBuildBT.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.stopBuildBT.Location = New System.Drawing.Point(320, 48)

Me.stopBuildBT.Name = "stopBuildBT"

Me.stopBuildBT.Size = New System.Drawing.Size(80, 23)

Me.stopBuildBT.TabIndex = 2

Me.stopBuildBT.Text = "Stop Build"

'

'buildProgress

'

Me.buildProgress.Location = New System.Drawing.Point(16, 24)

Me.buildProgress.Name = "buildProgress"

Me.buildProgress.Size = New System.Drawing.Size(296, 48)

Me.buildProgress.TabIndex = 1

'

'indexBT

'

Me.indexBT.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.indexBT.Location = New System.Drawing.Point(320, 16)

Me.indexBT.Name = "indexBT"

Me.indexBT.Size = New System.Drawing.Size(80, 23)

Me.indexBT.TabIndex = 0

Me.indexBT.Text = "Build Index"

'

'groupBox1

'

Me.groupBox1.Controls.Add(Me.label4)

Me.groupBox1.Controls.Add(Me.stopCrawlBT)

Me.groupBox1.Controls.Add(Me.crawlProgress)

Me.groupBox1.Controls.Add(Me.crawlBT)

Me.groupBox1.Controls.Add(Me.crawlURLTB)

Me.groupBox1.Controls.Add(Me.knownDocsTB)

Me.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.groupBox1.Location = New System.Drawing.Point(8, 72)

Me.groupBox1.Name = "groupBox1"

Me.groupBox1.Size = New System.Drawing.Size(408, 384)

Me.groupBox1.TabIndex = 8

Me.groupBox1.TabStop = False

Me.groupBox1.Text = "Crawl"

'

'label4

'

Me.label4.Location = New System.Drawing.Point(16, 72)

Me.label4.Name = "label4"

Me.label4.Size = New System.Drawing.Size(288, 16)

Me.label4.TabIndex = 5

Me.label4.Text = "Documents in database"

'

'stopCrawlBT

'

Me.stopCrawlBT.Enabled = False

Me.stopCrawlBT.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.stopCrawlBT.Location = New System.Drawing.Point(320, 56)

Me.stopCrawlBT.Name = "stopCrawlBT"

Me.stopCrawlBT.Size = New System.Drawing.Size(80, 23)

Me.stopCrawlBT.TabIndex = 4

Me.stopCrawlBT.Text = "Stop Crawl"

'

'crawlProgress

'

Me.crawlProgress.Location = New System.Drawing.Point(16, 48)

Me.crawlProgress.Name = "crawlProgress"

Me.crawlProgress.Size = New System.Drawing.Size(296, 24)

Me.crawlProgress.TabIndex = 3

'

'crawlBT

'

Me.crawlBT.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.crawlBT.Location = New System.Drawing.Point(320, 24)

Me.crawlBT.Name = "crawlBT"

Me.crawlBT.Size = New System.Drawing.Size(80, 23)

Me.crawlBT.TabIndex = 2

Me.crawlBT.Text = "Start Crawl"

'

'crawlURLTB

'

Me.crawlURLTB.Location = New System.Drawing.Point(16, 24)

Me.crawlURLTB.Name = "crawlURLTB"

Me.crawlURLTB.Size = New System.Drawing.Size(296, 20)

Me.crawlURLTB.TabIndex = 1

Me.crawlURLTB.Text = "http://localhost/KeyotiSearchDemo_VB"

'

'knownDocsTB

'

Me.knownDocsTB.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

Me.knownDocsTB.Location = New System.Drawing.Point(16, 96)

Me.knownDocsTB.Multiline = True

Me.knownDocsTB.Name = "knownDocsTB"

Me.knownDocsTB.ReadOnly = True

Me.knownDocsTB.ScrollBars = System.Windows.Forms.ScrollBars.Both

Me.knownDocsTB.Size = New System.Drawing.Size(384, 280)

Me.knownDocsTB.TabIndex = 3

Me.knownDocsTB.Text = "Known documents"

Me.knownDocsTB.WordWrap = False

'

'label1

'

Me.label1.Location = New System.Drawing.Point(8, 8)

Me.label1.Name = "label1"

Me.label1.Size = New System.Drawing.Size(688, 32)

Me.label1.TabIndex = 7

Me.label1.Text = "This demo is intended to give an overview of how to programmatically work with th" & _

"e search engine, it is not a user friendly indexing tool Please run Crawl, then " & _

"Build and then Search"

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(328, 40)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 13

Me.Button1.Text = "Button1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(928, 555)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.checkBox1)

Me.Controls.Add(Me.deleteIndexBT)

Me.Controls.Add(Me.groupBox3)

Me.Controls.Add(Me.groupBox2)

Me.Controls.Add(Me.groupBox1)

Me.Controls.Add(Me.label1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.groupBox3.ResumeLayout(False)

Me.groupBox2.ResumeLayout(False)

Me.groupBox1.ResumeLayout(False)

Me.ResumeLayout(False)

End Sub

#End Region

Sub on_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

UpdateKnownDocs()

End Sub

<STAThread()> _

Shared Sub Main()

Application.EnableVisualStyles()

Application.Run(New Form1)

End Sub

 

Public Sub FindDocs(ByVal theFoundItems As ArrayList, ByVal theRoot As String)

Dim theDirectories() As String = System.IO.Directory.GetDirectories(theRoot)

For Each theDirectory As String In theDirectories

FindDocs(theFoundItems, theDirectory)

Next

' Now scan the files in the current directory for any that match...

Dim theFiles() As String = System.IO.Directory.GetFiles(theRoot)

For Each theFile As String In theFiles

If theFile.ToLower().IndexOf(".pdf") > -1 Or theFile.ToLower().IndexOf(".doc") > -1 Then

theFoundItems.Add(theFile)

End If

Next

End Sub

 

 

 

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim docs As New ArrayList

FindDocs(docs, "C:\Inetpub\wwwroot")

'docs now has paths to all Doc and PDF files under wwwroot (careful, this method can take a long time)

'add the docs to the index

Keyoti.SearchEngine.Configuration.xmlLocation = indexDir

Try

indexer.Open()

Dim doc As String

For Each doc In docs

indexer.AddDocument(New Keyoti.SearchEngine.Documents.Document(New Keyoti.SearchEngine.DataAccess.DocumentRecord(New Uri(doc))))

Next

indexer.Close()

Catch ex As Exception

MessageBox.Show(("An error occurred: " + ex.Message))

End Try

MessageBox.Show("Recursive find ended")

'call UpdateKnownDocs() to refresh list of docs in index

UpdateKnownDocs()

End Sub

End Class



Related Questions:

Attachments:

No attachments were found.