Thursday, 26 June 2008

IIS : SMTP Email howto use telnet to test

>>telnet fic 26

220 FIC Microsoft ESMT
830 ready at Fri, 2 Dec 2005 09:24:56 +0000 mail Service, Version: 6.0.3790.1

>>HELO me.localdomain

250 FIC Hello [1.1.1.1]

>>mail FROM: example@example2.com

250 2.1.0 example@example2.com....Sender OK

>>RCPT TO: example2@example2.com

250 2.1.5 example2@example2.com

>>DATA

354 Start mail input; end with .

>>Just a test
>>.
>>

250 2.6.0 Queued mail f
or delivery

>>quit

221 2.0.0 FIC Service closing transmission channel

Monday, 23 June 2008

Javascript: Validate file extension when uploading files

/*check file extension*/
function CheckFileExtension(obj){
val=obj.value.substring(obj.value.length-4,obj.value.length);
  if (val!='.jpg'&&val!='.gif'&&val!='.bmp'&&val!='.png'&&val!='.jpeg'&&val!='.JPG'&&val!='.GIF'&&val!='.BMP'&&val!='.PNG'&&val!='.JPEG'){
   return false;
  }
}

Tuesday, 17 June 2008

ASP: URLDecode

' -----------------------------------------
' URL decode to retrieve the original value

Function URLDecode(sConvert)
Dim aSplit
Dim sOutput
Dim I
If IsNull(sConvert) Then
URLDecode = ""
Exit Function
End If

' convert all pluses to spaces
sOutput = REPLACE(sConvert, "+", " ")

' next convert %hexdigits to the character
aSplit = Split(sOutput, "%")

If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1
sOutput = sOutput & _
Chr("&H" & Left(aSplit(i + 1), 2)) &_
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If

URLDecode = sOutput
End Function

Indexing Service: Setting up indexing service

Stolen from http://www.cscoding.com/article/4/4017.html

Introduction




A lot of web sites provide search capabilities, where you can simple type
several words, press "Search" button, and you'll receive a list of pages which
contains these words. It's simple. But how can you implement these features in
your own web application? Yes, you have to use indexing service which will index
your files or web pages. After that you can use full text search
features.



There are a lot of solutions which allow you to provide this functionality in
your application. One of them is Microsoft Indexing Service. It's part of
Windows 2000 and later Windows versions. So, if you provide only Windows
solutions (ASP.NET web application, Windows Forms application, etc.) you have to
see this Microsoft's product.



On of the biggest goal of Indexing Service that it's totally free. You can
use it without any restriction or additional licenses. I think that this is so
big goal, because other indexing products cost a lot of money. If you develop
small or middle project you don't want to pay thousands dollars for full text
search tool.



If you will choose Indexing Service you should remember that it can index
only file system. For example, you can't use it for indexing files which stored
in your database. This is a big minus of Microsoft Indexing Service, but I
believe that you will solve this limitation.



In this manual I'll try to describe you how to install, configure and use
Microsoft Indexing Service. We'll develop simple application which will allow
you to use full text search features for web pages which located on your local
file system.




Installation and configuration Microsoft Indexing Service




If you are using Windows XP or later Windows version, you'll use Microsoft
Indexing Service 3.0. And if you're still using Windows 2000, you'll use
Microsoft Indexing Service 2.0. This service is installed to your machine by
default. But you could disable its installation, when you installed operating
system. You have to check that Indexing Service is installed on your machine. To
do this you go to "Add or Remove Programs" in your Control Panel. Choose
"Add/Remove Windows Components" there. You have to check that "Indexing Service"
is installed. If it isn't installed, install it, please.



Microsoft Indexing Service Installation



Now Microsoft Indexing Service has been installed, and you can configure it.
Please, open "Computer Management" configuration tool. Choose "Services and
Applications", "Indexing Service". In this entry you can manage your Microsoft
Indexing Service.



First of all you should create new catalog in Indexing Service for folder
which will contain indexes. Open context menu for "Indexing Service" and choose
"Catalog" in "New" submenu. You type "Name", choose "Location" and press
"OK".



New Catalog Creation



After that you have to add folders which will be indexed. For this choose
"Directories" entry, open its context menu and choose "Directory" in "New"
submenu. Choose folder with your documents in opened dialog box and press "OK"
button to include selected directory to the index. If you decide to exclude
folder from existing index, please choose "No" for "Include in Index?" parameter
in this dialog window. This parameter is "Yes" by default.



New Directory Creation



If your Indexing Service is started it will index new catalog. Otherwise you
should start Indexing Service and it will index catalog automatically. You can
create or recreate index folder manually. To do this you should open context
menu for specified folder in existing catalog and choose "Rescan (Full)" or
"Rescan (Incremental)" in "All Tasks" submenu. Of course, your Microsoft
Indexing Service has to be started at this time.



If you choose "Indexing Service" entry in your "Computer Management" you will
see state of the Indexing Service. Sometimes this information can help you if
you have big storage and can't find file there.



There is another important setting of Indexing Service – "Indexing Service
Usage". This setting allow you say Indexing Service how often it should update
indexes. For example, if you application use only static storage service have to
update index not so often as if you use dynamic data storage and your data is
updated very often. To configure this parameter you should open context menu for
"Indexing Service" entry and choose "Tune Performance" in "All Tasks"
submenu.



Indexing Service Usage Configuration



Now you can check index. To do this please choose "Query the Catalog" in your
catalog. You'll see form which allows you search something in your index. First
of all you can test simple full text search. Enter something in query field and
press "Search" button. After that you will see files which contain entered
words. Of course, you can execute more difficult queries using this tool. Choose
"Advanced query" if you want execute some queries. After that you can use
Microsoft Indexing Service queries to take some needed information. This query
language is the same language as SQL, but it contains some syntax
extensions.




Query Microsoft Indexing Service




You can use SQL to query Microsoft Indexing service. But there are several
extensions for Indexing Service's SQL dialect which you have to know.



The most useful command, when you use Microsoft Indexing Service, is SELECT
command. It's clear, because you shouldn't add, delete or update information in
your indexes. You only select query Indexing Service to retrieve some
information about indexed files.Let's see example query:


SELECT Path FROM SCOPE() WHERE FREETEXT(Contents, 'Hello World')<br /></pre><br />
<p>This query returns you all paths to files which contain "Hello World" text.
And it can help me describe you Microsoft Indexing Service's SQL
extensions.</p><br />
<p>First of all let's speak about <em>FROM</em> expression. In this example we
query all data which index contain. <em>SCOPE()</em> function allows you tell
Indexing Service which data you decide to examine. By default, if you don't use
any parameters, it examines all data in your index. This function can optimize
your queries, because it can limit indexes for search. For example, you can use
<em>SCOPE ('"/books"') </em>. At this time you will query only "/books" folder,
not all folders in your index. Query execution speed will be more that if you
would use simple <em>SCOPE()</em> function. For more search limitation you can
use special traversal types. For example, <em>SCOPE ('DEEP TRAVERSAL OF
"/books"') </em>. If you use this expression, Indexing Service will search in
"/books" directory and in all directories beneath them. If you use <em>SHALLOW
TRAVERSAL</em> Microsoft Indexing service will examine only "/books" directory.
For example, <em>SCOPE('SHALLOW TRAVERSAL OF "/books"') </em>.</p><br />
<p><em>WHERE</em> expression is the same as in SQL standard, but there are few
extensions for it too. There are Comparison Predicates. You can see they in this
table:</p><br />
<table border="1" cellspacing="0" width="60%"><br />
<tbody>
<tr style="background-color: silver;"><br />
<td>Operator</td><br />
<td>Symbol</td><br />
<td>Example</td><br /></tr><br />
<tr><br />
<td>Equals</td><br />
<td>=</td><br />
<td><em>WHERE DocAuthor = 'John Doe'</em></td><br /></tr><br />
<tr><br />
<td>Not equals</td><br />
<td>!= or <></td><br />
<td><em>WHERE DocTitle != 'Finance'</em></td><br /></tr><br />
<tr><br />
<td>Less than</td><br />
<td><</td><br />
<td><em>WHERE WordCount < 1000</em></td><br /></tr><br />
<tr><br />
<td>Greater than</td><br />
<td>></td><br />
<td><em>WHERE WordCount > 500</em></td><br /></tr><br />
<tr><br />
<td>Less than or equal to</td><br />
<td><=</td><br />
<td><em>WHERE WordCount <= 500</em></td><br /></tr><br />
<tr><br />
<td>Greater than or equal to</td><br />
<td>>=</td><br />
<td><em>WHERE WordCount >= 500</em></td><br /></tr><br /></tbody></table><br />
<p>You also can use Boolean operators which are evaluated using following
rules:</p><br />
<ul><br /><li><em>NOT</em> is evaluated before <em>AND</em>. <em>NOT</em> can only occur
after <em>AND</em> (as in <em>AND NOT</em>; the combination <em>OR NOT</em> is
not allowed). <br />
</li><li><em>AND</em> is evaluated before <em>OR</em>. <br />
</li><li><em>AND</em> expressions are associative and can be applied in any order.
For example, <em>A AND B AND C</em>, is the same as <em>(A AND B) AND C</em>,
which is the same as <em>A AND (B AND C) </em>. <br />
</li><li><em>OR</em> expressions are associative and can be applied in any order.
<br /></li></ul><br />
<p>There is LIKE predicate too. But there are several predicates which extend
SQL language:</p><br />
<ul><br /><li><em>ARRAY</em>. This predicate performs comparisons of two arrays using
logical operators. For example, <em>... WHERE username = SOME ARRAY ['Admin' ,
'root'] </em>. This example returns you files which contain username parameter
and this parameter is 'Admin' or 'root'. <br />
</li><li><em>CONTAINS</em>. This predicate using for full text search. For example,
<em>…WHERE CONTAINS(country,'"USA" OR "Russia"') </em>. This example return
files, which contains country property and this property is "USA" or "Russia".
<br />
</li><li><em>FREETEXT</em>. This predicate allows you find words and phrases in
indexed files. It's better to use it if you need find anything in the content of
your files. For example, <em>…WHERE CONTAINS(Contents,'Hello World !!!') </em>.
<br />
</li><li><em>MATHCES</em>. Predicate performs queries using regular-expression
pattern. It's more powerful than <em>LIKE</em> predicate. For example, <em>…
WHERE MATCHES (Contents, '|(USA|)|{1|}' ) </em>. This example matches any string
in which exactly one instance of the pattern "BUSA" occur. <br /></li></ul><br />
<p>For additional information you have to see <a href="http://msdn2.microsoft.com/en-us/library/aa163263.aspx">Indexing Service
Articles on MSDN web site</a>.</p><br />
<p>Now you know how to prepare queries to Microsoft Indexing Service, but you
still need take list of properties, which can be used in your queries. There are
a lot of default properties for each index, which you can find in following
table.</p><br />
<table border="1" cellspacing="0" width="60%"><br />
<tbody>
<tr style="background-color: silver;"><br />
<td>Friendly Name</td><br />
<td>Datatype</td><br />
<td>Property</td><br /></tr><br />
<tr><br />
<td>A_HRef</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML HREF. This property name was created for Microsoft® Site Server
and corresponds with the Indexing Service property name HtmlHRef. Can be queried
but not retrieved.</td><br /></tr><br />
<tr><br />
<td>Access</td><br />
<td>VT_FILETIME</td><br />
<td>Last time file was accessed.</td><br /></tr><br />
<tr><br />
<td>All</td><br />
<td>(not applicable)</td><br />
<td>Searches every property for a string. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>AllocSize</td><br />
<td>DBTYPE_I8</td><br />
<td>Size of disk allocation for file.</td><br /></tr><br />
<tr><br />
<td>Attrib</td><br />
<td>DBTYPE_UI4</td><br />
<td>File attributes. Documented in Win32 SDK.</td><br /></tr><br />
<tr><br />
<td>ClassId</td><br />
<td>DBTYPE_GUID</td><br />
<td>Class ID of object, for example, WordPerfect, Word, and so
on.</td><br /></tr><br />
<tr><br />
<td>Characterization</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Characterization, or abstract, of document. Computed by Indexing
Service.</td><br /></tr><br />
<tr><br />
<td>Contents</td><br />
<td>(not applicable)</td><br />
<td>Main contents of file. Can be queried but not retrieved.</td><br /></tr><br />
<tr><br />
<td>Create</td><br />
<td>VT_FILETIME</td><br />
<td>Time file was created.</td><br /></tr><br />
<tr><br />
<td>Directory</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Physical path to the file, not including the file name.</td><br /></tr><br />
<tr><br />
<td>DocAppName</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Name of application that created the file.</td><br /></tr><br />
<tr><br />
<td>DocAuthor</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Author of document.</td><br /></tr><br />
<tr><br />
<td>DocByteCount</td><br />
<td>DBTYPE_14</td><br />
<td>Number of bytes in a document.</td><br /></tr><br />
<tr><br />
<td>DocCategory</td><br />
<td>DBTYPE_STR | DBTYPE_BYREF</td><br />
<td>Type of document such as a memo, schedule, or whitepaper.</td><br /></tr><br />
<tr><br />
<td>DocCharCount</td><br />
<td>DBTYPE_I4</td><br />
<td>Number of characters in document.</td><br /></tr><br />
<tr><br />
<td>DocComments</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Comments about document.</td><br /></tr><br />
<tr><br />
<td>DocCompany</td><br />
<td>DBTYPE_STR | DBTYPE_BYREF</td><br />
<td>Name of the company for which the document was written.</td><br /></tr><br />
<tr><br />
<td>DocCreatedTm</td><br />
<td>VT_FILETIME</td><br />
<td>Time document was created.</td><br /></tr><br />
<tr><br />
<td>DocEditTime</td><br />
<td>VT_FILETIME</td><br />
<td>Total time spent editing document.</td><br /></tr><br />
<tr><br />
<td>DocHiddenCount</td><br />
<td>DBTYPE_14</td><br />
<td>Number of hidden slides in a Microsoft® PowerPoint
document.</td><br /></tr><br />
<tr><br />
<td>DocKeywords</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Document keywords.</td><br /></tr><br />
<tr><br />
<td>DocLastAuthor</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Most recent user who edited document.</td><br /></tr><br />
<tr><br />
<td>DocLastPrinted</td><br />
<td>VT_FILETIME</td><br />
<td>Time document was last printed.</td><br /></tr><br />
<tr><br />
<td>DocLastSavedTm</td><br />
<td>VT_FILETIME</td><br />
<td>Time document was last saved.</td><br /></tr><br />
<tr><br />
<td>DocLineCount</td><br />
<td>DBTYPE_14</td><br />
<td>Number of lines contained in a document.</td><br /></tr><br />
<tr><br />
<td>DocManager</td><br />
<td>DBTYPE_STR | DBTYPE_BYREF</td><br />
<td>Name of the manager of the document's author.</td><br /></tr><br />
<tr><br />
<td>DocNoteCount</td><br />
<td>DBTYPE_14</td><br />
<td>Number of pages with notes in a PowerPoint document.</td><br /></tr><br />
<tr><br />
<td>DocPageCount</td><br />
<td>DBTYPE_I4</td><br />
<td>Number of pages in document.</td><br /></tr><br />
<tr><br />
<td>DocParaCount</td><br />
<td>DBTYPE_14</td><br />
<td>Number of paragraphs in a document.</td><br /></tr><br />
<tr><br />
<td>DocPartTitles</td><br />
<td>DBTYPE_STR | DBTYPE_VECTOR</td><br />
<td>Names of document parts. For example, in Excel part titles are the names of
spread sheets, in PowerPoint slide titles, and in Word for Windows the names of
the documents in the master document.</td><br /></tr><br />
<tr><br />
<td>DocPresentationTarget</td><br />
<td>DBTYPE_STR | DBTYPE_BYREF</td><br />
<td>Target format (35mm, printer, video, and so on) for a presentation in
PowerPoint.</td><br /></tr><br />
<tr><br />
<td>DocRevNumber</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Current version number of document.</td><br /></tr><br />
<tr><br />
<td>DocSlideCount</td><br />
<td>DBTYPE_14</td><br />
<td>Number of slides in a PowerPoint document.</td><br /></tr><br />
<tr><br />
<td>DocSubject</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Subject of document.</td><br /></tr><br />
<tr><br />
<td>DocTemplate</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Name of template for document.</td><br /></tr><br />
<tr><br />
<td>DocTitle</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Title of document.</td><br /></tr><br />
<tr><br />
<td>DocWordCount</td><br />
<td>DBTYPE_I4</td><br />
<td>Number of words in document.</td><br /></tr><br />
<tr><br />
<td>FileIndex</td><br />
<td>DBTYPE_I8</td><br />
<td>Unique ID of file.</td><br /></tr><br />
<tr><br />
<td>FileName</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Name of file.</td><br /></tr><br />
<tr><br />
<td>HitCount</td><br />
<td>DBTYPE_I4</td><br />
<td>Number of hits (words matching query) in file.</td><br /></tr><br />
<tr><br />
<td>HtmlHRef</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML HREF. Can be queried but not retrieved.</td><br /></tr><br />
<tr><br />
<td>HtmlHeading1</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML document in style H1. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>HtmlHeading2</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML document in style H2. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>HtmlHeading3</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML document in style H3. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>HtmlHeading4</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML document in style H4. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>HtmlHeading5</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML document in style H5. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>HtmlHeading6</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Text of HTML document in style H6. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>Img_Alt</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Alternate text for <IMG> tags. Can be queried but not
retrieved.</td><br /></tr><br />
<tr><br />
<td>Path</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Full physical path to file, including file name.</td><br /></tr><br />
<tr><br />
<td>Rank</td><br />
<td>DBTYPE_I4</td><br />
<td>Rank of row. Ranges from 0 to 1000. Larger numbers indicate better
matches.</td><br /></tr><br />
<tr><br />
<td>RankVector</td><br />
<td>DBTYPE_I4 | DBTYPE_VECTOR</td><br />
<td>Ranks of individual components of a vector query.</td><br /></tr><br />
<tr><br />
<td>ShortFileName</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Short (8.3) file name.</td><br /></tr><br />
<tr><br />
<td>Size</td><br />
<td>DBTYPE_I8</td><br />
<td>Size of file, in bytes.</td><br /></tr><br />
<tr><br />
<td>USN</td><br />
<td>DBTYPE_I8</td><br />
<td>Update Sequence Number. NTFS drives only.</td><br /></tr><br />
<tr><br />
<td>VPath</td><br />
<td>DBTYPE_WSTR | DBTYPE_BYREF</td><br />
<td>Full virtual path to file, including file name. If more than one possible
path, then the best match for the specific query is chosen.</td><br /></tr><br />
<tr><br />
<td>WorkId</td><br />
<td>DBTYPE_I4</td><br />
<td>Internal ID for file. Used within Indexing Service.</td><br /></tr><br />
<tr><br />
<td>Write</td><br />
<td>VT_FILETIME</td><br />
<td>Last time file was written.</td><br /></tr><br /></tbody></table><br />
<p>As you can see, there are a lot indexed properties for each file, but
sometime you want to extend this list.</p><br /><br />
<h2>How to add new properties for indexed file</h2><br /><br />
<p>First of all I have to say, that this feature works only for web pages,
because it is base on HTML <em><meta></em> tag.</p><br />
<p>Now you have several indexed web pages and you want to add several special
properties for them. For example, you will add "country" and "city" properties.
First of all you should add <em><meta></em> tags to all files which will
contain these new properties:</p><br /><pre lang="html"><meta name="country" content="Russia" /><br /><br /><meta name="city" content="Moscow" /><br /><br /></pre><br />
<p>After these changes you have to restart Indexing Service. Now you can open
entry "Properties" and see that right now Microsoft Indexing Service knows about
your special parameters for files. But still you can't use these new parameters
in queries.</p><br />
<p>Select "Properties" node of your catalog and choose property, which you added
to the files using <em><meta></em> tag. Double click on this property.
Switch on "Cached" checkbox and choose data type for new property in opened
dialog box.</p><br />
<p><img alt="Microsoft Indexing Service Installation" src="http://file.cscoding.com/file/8%5C4017%5CMicrosoft_Indexing_Service_HOW_TO5.jpg" /></p><br />
<p>After that you should create Column Definition File which contains
information about your new added parameters. File could have ".idq" extension,
but this isn't important. Column Definition File uses following format:</p><br /><pre>[Names]<br />Propertyname( Data type ) = GUID [<span class="cpp-string">"Name"</span> | Property ID] <br /></pre><br />
<p>Data type parameter is optional. If you don't define it, Microsoft Indexing
Service will take data type from parameters definition for your catalog.</p><br />
<p>For my example it contains this:</p><br /><pre>[Names]<br />country = d1b5d3f0-c0b3-11cf-9a92-00a0c908dbf1 <span class="cpp-string">"country"</span><br />city = d1b5d3f0-c0b3-11cf-9a92-00a0c908dbf1 <span class="cpp-string">"city"</span><br /></pre><br />
<p>All these data you can take from dialog box for properties
configuration.</p><br />
<p>After Columns Definition File is created, information about this file has to
be added to Indexing Service registry settings. Add String entry named
<em>"DefaultColumnFile" </em>to the registry key
<em>"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndexCommon"</em>.
<em>"DefaultColumnFile" </em>should contain full path to your Columns Definition
File.</p><br />
<p>Restart Microsoft Indexing Service. After that run full rescan of your
indexed folder. Now you are able to use these new parameters in your
queries.</p><br /><br />
<h2>Using Microsoft Indexing Service in .NET applications</h2><br /><br />
<p>Microsoft Indexing Service exposes itself to the developer as OLE DB
provider. Its name is MSIDXS. You can use ADO.NET for query you Indexing
Service. To do this you have to create new System.Data.OleDb.OleDbConnection
object using this sample connection string:</p><br /><pre>Provider= <span class="cpp-string">"MSIDXS"</span>;Data Source=<span class="cpp-string">"Documents"</span><br /></pre><br />
<p>In Data Source parameter you should use name of your catalog in indexing
Service.</p><br />
<p>Let's create sample code which will query Indexing Service for few words in
files' contents. <br />In this sample there is queryString variable. It is an
instance of SearchParameters structure. This structure contains information
about Data Source and Query string. Here is the definition of this
structure:</p><br /><pre lang="cs">struct SearchParameters<br />{<br /> private string storage;<br /><br /> public string Storage<br /> {<br /> get { return storage; }<br /> set { storage = value; }<br /> }<br /><br /> private string query;<br /><br /> public string Query<br /> {<br /> get { return query; }<br /> set { query = value; }<br /> }<br />}<br /></pre><br />
<p>First of all you create new OleDbConnection object:</p><br /><pre lang="cs">string connectionString = string.Format(<span class="cpp-string">"Provider= \"</span>MSIDXS\<span class="cpp-string">";Data Source=\"</span>{0}\<span class="cpp-string">";"</span>, queryString.Storage);<br />OleDbConnection connection = new OleDbConnection(connectionString);<br /></pre><br />
<p>After that you create new OleDbCommand which associated with this
connection:</p><br /><pre lang="cs">string query = string.Format(@<span class="cpp-string">"SELECT Path FROM scope() WHERE FREETEXT(Contents, '{0}')"</span>, queryString.Query);<br />OleDbCommand command = new OleDbCommand(query, connection); <br /></pre><br />
<p>Note that MSIDXS provider doesn't support commands with parameters. This is
bad. I hope that Microsoft will fix this issue in next version of Microsoft
Indexing Service.</p><br />
<p>Now you are able to execute this command and retrieve list of files which
contain selected text:</p><br /><pre lang="cs">connection.Open();<br /><br />ArrayList result = new ArrayList();<br /><br />OleDbDataReader reader = command.ExecuteReader();<br />while (reader.Read())<br />{<br /> result.Add(reader.GetString(0));<br />}<br /><br />connection.Close();<br />


In this code checking returned value to NULL is not necessary, because
Indexing Service always returns path to found file.




Summary




Microsoft Indexing Service is totally free and powerful product which
included to Windows 2000 or later Windows versions. But it's simple very much.
You can easy create indexes. You can also query these indexes using OLE DB data
provider. If you are working with Microsoft .NET it will easy very much. In this
article I tried to describe you how to install, configure and query. I also
recommend you see my example, which I attached to this manual. This example will
show you how to use full text search features. I hope that this article will
help you to start using Indexing Service.