Last week I downloaded the WinFS SDK (BETA 1) and installed it but quickly discovered that I was too time poor to spend any time experimenting with it. This week I’ve found a few spare moments to get familiar with the programming interface. My first challenge was putting some data into the DefaultStore which is pretty much a case of just dragging and dropping it in Windows Explorer. I could have added them programmatically but this was easier.

Then I set about writing a program to search for the files. This was also pretty straight-forward after reading the documentation and getting some hints from the samples. I produced the following little command line application which prompts for a search term and then displays a list of hits on the screen.

SearchResults

I think the hardest thing about doing the search is knowing what to filter on. In the particular documents that I was working with none of the document properties had been filled in so there wasn’t really a lot to search on. I ended filtering on NamespaceName which as far as I can tell is actually the filename, neither DisplayName or Title worked for me in this instance. Anyway, here is the code:

  1             using (WinFSData data = new WinFSData(@"\\localhost\DefaultStore\Users"))
  2             {
  3                 Console.Write("Please enter item name: ");
  4                 string itemName = Console.ReadLine();
  5                 Console.WriteLine();
  6 
  7                 StorageSearcher<Item> searcher = data.Items.Filter(
  8                     "NamespaceName like @0",
  9                     string.Format("%{0}%", itemName)
 10                     );
 11                 foreach (Item document in searcher)
 12                 {
 13                     Console.WriteLine(document.NamespaceName);
 14                 }
 15 
 16                 Console.WriteLine();
 17                 Console.WriteLine("Found {0} document(s).", searcher.GetCount());
 18             }
 19