Wednesday, September 26, 2007

using Indexing Server from .NET

I had to write the Indexing Server code to search within the file in VB6 and I again had to write it but this time in .net. Following is the Simplest way we can get the same thing done in .NET.
You have to have your Catalog created in your Indexing Server in Component Management Console (Start->run->Compmgmt.msc)

string strCat = "DWF"; //Your Catalog in Index Server
string strQuery = "Select DocTitle,Filename,Size,PATH,URL from SCOPE() where FREETEXT('" + Convert.ToChar(34) + text + Convert.ToChar(34) + "')";
//CONTAINS(Contents, '" + TextBox1 + "')";
//FREETEXT('" + TextBox1.Text + "')";
string conStr = "Provider=MSIDXS.1;Integrated Security .='';Data Source='" + strCat + "'";
cn.ConnectionString = conStr;
cn.Open();
OleDbDataAdapter DA = new OleDbDataAdapter(strQuery, cn);
DataSet testDataSet = new DataSet();
DA.Fill(testDataSet);
//Bind DataGrid to the DataSet. DataGrid is the ID for the
//DataGrid control in the HTML section.

DataView source = new DataView(testDataSet.Tables[0]);
GridView1.DataSource = source;
GridView1.DataBind();

Enjoy!!

No comments: