How to index app local data

Applies to Windows only

You can index the local stored data for your app via the Windows Search Service (WSS).

If your app manages files such as documents, mail, or media (photo, music, video, and so on), there is a central requirement to index the contents or properties of the files structurally, so that users are able to manage and retrieve the data in a quick and efficient fashion. You don't need to build the indexer within your app. There is a convenient and secure option for you as the app developer: you can just enable WSS to index your app data.

The main advantages in using WSS to index your app data are:

  • WSS supports indexing the full content text of most commonly used document types. In addition, WSS also supports indexing the file properties.
  • With built-in search contract and file APIs, indexed data can be easily fetched and reused.
  • Windows search respects the file system security settings, which maintain the indexed app data securely stored in the Windows indexer.
Windows Search works with all Windows Store apps, including those written using JavaScript, C#, C++, and VB.Net.

Enabling Windows search for your app

Requesting Windows search to index the app data is effortless. You need to create a folder named indexed under the app data folder and store the contents that need to be indexed within. Windows search treats the indexed folder just like any other indexing location on the hard drive. It will index the file contents or file metadata (properties) in this folder and all its subfolders. Here is a list of important considerations :

  1. The indexed folder must follow these guidelines:
    • The indexed folder must be created under localFolder root. Windows search does index the contents in this folder deeply. Any file that is locally stored in this folder or its subfolders (including all levels of subfolders) will be indexed. Only one indexed folder per app is allowed.
    • The folder name indexed is not case sensitive.
    • Although the app data folder is called localFolder in the Windows Runtime API, it is named LocalState on the physical hard drive. If you want to access this folder for testing purposes, use this folder path : %user%\ AppData\Local\Packages\%packageName%\LocalState
    • The folder structure under the indexed can be deep, but the Windows API doesn’t allow the length of the path for a file/folder longer than MAX_PATH, which is defined as 260 characters. So you need to ensure that the files or folders under the indexed folder don't exceed this limit. For more info about MAX_PATH, see Maximum Path Length Limitation.
  2. Windows search only indexes the local stored data. In other words, only the files that are locally stored in the indexed folder or its subfolders will be indexed.
  3. The indexed folder can't be created during installation. It can only be created when the app is running. Because it takes time for Windows search to complete, depending on the content size, we recommend that you create the indexed folder when the app is first run. After you create the indexed folder, Windows search will automatically index the app content. If the files or subfolders are modified (added, deleted or updated) , Windows search will also automatically reschedule an indexing process and keep the indexer updated with the changes. Note that Windows search monitors the CPU usage to optimize the indexing process on its own schedule.

Security

WSS respects the security settings of the Windows file system such that the indexed app data are stored in indexer securely. In particular:

  • When multiple user accounts are on the same PC: Windows Store apps are installed per user account. If there are multiple users on the same PC using the same app, each app instance would create its own indexed folder under a different physical path. So one user can't access the indexed data under other accounts unless this user is granted the access to that physical path.
  • When app data for multiple apps is indexed: Windows file system doesn't allow one app to access the data of another app directly. So an app doesn't have access to another app’s indexed data.

Fetching indexed content

After the app data is indexed, the app can fetch the data via the file API.

Related topics

Windows Search Service
How Windows Search Service index the content via IFilters
Adding search to Windows Store apps

 

 

Show:
© 2014 Microsoft