Calling the WDS API from VB .NET
This post was from my old blog. Click here for the original post (with original comments).
Some people in the Aqua-Soft forum had questions about how to call the Windows Desktop Search API from VB .NET. There are two ways to do this right now, using our beta SDK.
1) Download the SDK and Sample (see my post below) files. Reference WDSQuery.dll and include QueryBuilder.cs in your project. Then you can instantiate a QueryBuilder object and use that (the comments in that file, or IntelliSense, will guide you). It’s pretty simple.
2) Use the COM API directly. Here’s what I posted over there:
Open VS 2003 and create a new VB.NET “Windows Forms” project. Add a reference to WDSQuery.dll.
Drop a DataGrid control from the toolbox onto the form, and size it reasonably. Leave the name as “DataGrid1” for now.
Copy and paste this code into the vb file:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mSearchClass As New Microsoft.Windows.DesktopSearch.Query.SearchDesktopClass
Dim resultSet As Microsoft.Windows.DesktopSearch.Query._Recordset
resultSet = mSearchClass.ExecuteQuery(“test”, “DocTitle,DocAuthor,Url”, “DocTitle”, Nothing)
Dim DataSet1 As New System.Data.DataSet
Dim DataTable1 As New System.Data.DataTable
Dim DataAdapter1 As New System.Data.OleDb.OleDbDataAdapter
DataGrid1.DataSource = DataSet1
DataGrid1.DataMember = “Table1”
Build and run. Your datagrid should be filled with results for the query “test” – you can of course change that to something more pertinent to your index.
VB isn’t really my thing, but that works on my system and should give you a basic idea of how to use the COM interfaces.
Option 1 is nice because QueryBuilder gives you easier query syntax to work with, and it gives you a decent list of Column Names that are supported in the current release (2.05) – remember, these are subject to change in future releases.
C# developers have a little easier time because they can read the sample code but not necessarily use it verbatim. If you don’t understand C# though it may not be as useful to you – it really depends on your usage.
I’ll be posting more about the SDK soon. Tomorrow my cable gets installed at the new apartment, so I’ll actually be able to leave the office and get more blogging done 🙂