Using Index Server for ASP.NET Site Search

This projects highlights how to add search facility to your ASP.NET page using ADO.NET to browse index server search catalogs.


This is a sample project made to help developers. This projects highlights how to add search facility to your page using to browse index server search catalogs. To be able to understand this , developer should have knowledge of using to show the data on the Page.


This code is developed to enable search facilities to applications. This is a easy to use as only with few lines of code you will be able provide dynamism to your applications. It works like accessing a query from database. Before starting this project , you must create a catalog using the Index Server. To read more details how to create and configure catalogs

Table Format

Heading  Heading
using Index Server Search in This is a sample project made to help developers. This projects highlights how to add search facility to your page using to browse index server search catalogs. To be able to understand this , developer should have knowlege of using to show the data on the Page.

Create Catalog :
To create a catalog
  1. In the MMC, select Index Server.
  2. From the Action menu, select Stop.

    You must stop the Content Index service before you can add a catalog.
  3. From the Action menu, select Create New and then Catalog.
  4. In the Add Catalog dialog box, type the name of the catalog.
  5. Click the Browse button and select a directory where you want this new catalog to be located.
  6. When you have selected the catalog location, click the OK button.
  7. With Index Server selected, from the Action menu, select Start.

    Restarting Index Server makes the new catalog available for the indexing process.

Note : Before you can add a new catalog, you must stop Index Server. After you create a new catalog, you must restart Index Server to bring the new catalog online. But before bringing it online, you may want to add directories and modify catalog properties.
Summary using catalog in
This project is development using following packages in the Application with Csharp.
using System.Data.OleDb;
ASPX page contains one textbox , Button and label on the page
form id="search" method="post" runat="server">
<TABLE id="Table3" cellSpacing="1" cellPadding="1" width="95%" align="right" border="0">
<asp:Label id="Label1" runat="server">Search Site</asp:Label>
<asp:TextBox id="txtSearch" runat="server"></asp:TextBox>
<asp:Button id="btnSearch" runat="server" Text="Search"></asp:Button><BR>
<asp:Label id="lbl" runat="server"></asp:Label></P>

System.Web.UI.WebControls.TextBox txtSearch; protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.Label lbl;
public int cnt;
/// On the click of button, search for the keyword in the index catalog , and show the matching result on the page /// </SUMMARY>
/// <PARAM name="sender"></PARAM>
/// <PARAM name="e"></PARAM>
private void btnSearch_Click(object sender, System.EventArgs e)
// connecting string for connecting index server, In this provider name is MSIDXS ; DataSource is name of the catalog name in the index server.
// create a connection object and command object, to connect the Index Server
System.Data.OleDb.OleDbConnection odbSearch = new System.Data.OleDb.OleDbConnection(); System.Data.OleDb.OleDbCommand cmdSearch = new System.Data.OleDb.OleDbCommand(); 
//assign the connecting string to the oledb connection object , replace Catalog Name with the name of index catalog created earlier
odbSearch.ConnectionString = "Provider=\"MSIDXS\";Data Source=\"[Catalog name]\";";
//assign connection to command object cmdSearch
cmdSearch.Connection = odbSearch;
//Query to search a free text string in the catalog in the contents of the indexed documents in the catalog
// Make freetext search in the contents and retreive document titles , path , rank from the index catalog
cmdSearch.CommandText = "select doctitle, filename, vpath, rank, characterization from scope() where FREETEXT(Contents, '"+txtSearch.Text +"') and filename <> 'search.aspx' order by rank desc ";
OleDbDataReader rdrSearch = cmdSearch.ExecuteReader();
//dg1.DataSource=rdrSearch; //dg1.DataBind(); cnt=1;
// your databinding or display code here
while( rdrSearch.Read())
// Call method get pagelink to write process and show the valid link on the page , here we have used getpagelink to show the file name searched
catch(Exception ex)
lbl.Text=ex.Message ;
catch( SqlException ex)
/// This function creates the link of the searched document in the predefined template.
/// </SUMMARY>
/// <PARAM name="srcfile">This Function is </PARAM>
public void getpagelink(string srcfile)
string temp= (cnt).ToString() +".) " + srcfile;

To customize your pages , you can put several Headers and other HTML Tags to make it familiar to your pages, In case you have already fixed your templates you can make a user control instead of making a ASPX page and then add User control to any of webforms and load them, using this technique.
To test this page  type keyword in the text box and click the button given on the page and wait for the page response.