Click here to Skip to main content
14,737,867 members
Articles » Web Development » ASP.NET » General
Posted 5 Sep 2019

Tagged as


5 bookmarked

Windows Search ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
5 Sep 2019CPOL
This application shows how to search Windows Index in ASP.NET.


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.

Image 1

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)

        Catch ex As Exception
            Response.Write(ex.Message & "; ConnectionString: " & sConnectionString)
        End 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
            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)
                Response.Write("</tr></thead><tbody>" & vbCrLf)
                For iRow As Integer = 0 To oTable.Rows.Count - 1
                    For iCol As Integer = 0 To oTable.Columns.Count - 1
                        Response.Write("<td>" & _
                        oTable.Rows(iRow)(iCol) & "</td>" & vbCrLf)
            End If
        Catch ex As Exception
            Response.Write("<div class='alert alert-danger' _
                             style='margin-top: 10px;'>" & ex.Message & "</div>")
        End Try
End If

Windows Search

Windows Search lets you search contents of the files.

  1. Make sure that "Windows Search" service is running:

    Image 2

  2. Make sure your folder is added under "Indexing Options". Go to: Control Panel > Indexing Options.

    Image 3

  3. 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.

    Image 4

  4. You can test the index by doing content search in Windows Explorer. In the top right corner, type "Content:" followed by file content.

    Image 5

  5. If you cannot find the file, you can manually rebuild the index:

    Image 6

  6. The Windows Search index is stored in "C:\ProgramData\Microsoft\Search\Data\Applications\Windows\Windows.edb" and can be moved to another location.

    Image 7


  • 5th September, 2019: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Igor Krupitsky
Web Developer
United States United States
Igor is a business intelligence consultant working in Tampa, Florida. He has a BS in Finance from University of South Carolina and Masters in Information Management System from University of South Florida. He also has following professional certifications: MCSD, MCDBA, MCAD.

Comments and Discussions

-- There are no messages in this forum --