Windows Search ASP.NET





5.00/5 (3 votes)
This application shows how to search Windows Index in ASP.NET.
Introduction
This application shows how to search Windows Index in ASP.NET. Windows Search builds a full-text index of files on a computer. This application lets you search by file contents and file attributes.
Using the Code
The code uses OleDb Search.CollatorDSO
provider to communicate with the Windows Search service on the local or remote computer.
Dim sFolder As String = "C:\Igor\ReportPortal"
Dim sServerName As String = ""
If Left(sFolder, 2) = "\\" Then
'Search File Sahre
sServerName = sFolder.Substring(2)
Dim iPos As Integer = sServerName.IndexOf("\", 3)
sServerName = """" & sServerName.Substring(0, iPos) & """."
sFolder = Replace(sFolder, "\", "/")
If Right(sFolder, 1) <> "/" Then
sFolder += "/"
End If
End If
If Request.Form("txtSql") <> "" Then
Dim sConnectionString As String = "Provider=Search.CollatorDSO;_
Extended Properties=""Application=Windows"""
Dim cn As New System.Data.OleDb.OleDbConnection(sConnectionString)
Try
cn.Open()
Catch ex As Exception
Response.Write(ex.Message & "; ConnectionString: " & sConnectionString)
End Try
Try
Dim ad As System.Data.OleDb.OleDbDataAdapter = _
New System.Data.OleDb.OleDbDataAdapter(Request.Form("txtSql"), cn)
Dim ds As System.Data.DataSet = New System.Data.DataSet
ad.Fill(ds)
If ds.Tables.Count > 0 Then
Dim oTable As System.Data.DataTable = ds.Tables(0)
Response.Write("<table class='table table-striped'><thead><tr>")
For iCol As Integer = 0 To oTable.Columns.Count - 1
Response.Write("<th>" & _
oTable.Columns(iCol).Caption & "</th>" & vbCrLf)
Next
Response.Write("</tr></thead><tbody>" & vbCrLf)
For iRow As Integer = 0 To oTable.Rows.Count - 1
Response.Write("<tr>")
For iCol As Integer = 0 To oTable.Columns.Count - 1
Response.Write("<td>" & _
oTable.Rows(iRow)(iCol) & "</td>" & vbCrLf)
Next
Response.Write("</tr>")
Next
Response.Write("</tbody></table>")
End If
Catch ex As Exception
Response.Write("<div class='alert alert-danger' _
style='margin-top: 10px;'>" & ex.Message & "</div>")
End Try
cn.Close()
End If
Windows Search
Windows Search lets you search contents of the files.
- Make sure that "Windows Search" service is running:
- Make sure your folder is added under "Indexing Options". Go to: Control Panel > Indexing Options.
-
Check PDF Filter. Install PDF Filter if it is missing from Adobe.
Check office files (docx, xlsx, pptx) filters. Install. Microsoft Office 2010 Filter Packs if they are missing.
- You can test the index by doing content search in Windows Explorer. In the top right corner, type "Content:" followed by file content.
- If you cannot find the file, you can manually rebuild the index:
- The Windows Search index is stored in "C:\ProgramData\Microsoft\Search\Data\Applications\Windows\Windows.edb" and can be moved to another location.
History
- 5th September, 2019: Initial version