Search code examples
c#visual-studiovisual-studio-2012microsoft-metrofilesystemwatcher

Can't use FileSystemWatcher in Visual Studio 2012


I am new to Visual Studio and C#. I am used to using XCode and Objective-C but am now trying to write a Windows 8 app. I am trying to set up a FileSystemWatcher when the user clicks a button in my app, but for some reason Visual Studio refuses to recognize that I can do it and throws an error. Here is a sample of what I have written:

using System;
using System.IO;
...

namespace My_APP
{
...
    public sealed partial class MainPage : My_App.Common.LayoutAwarePage
    {
    ...
        public void button_click_1(object sender, RoutedEventArgs e)
        {
            FileSystemWatcher watch = new FileSystemWatcher();
        }
    }
}

The FileSystemWatcher is underlined both times in red with the error: Error 1 The type or namespace name 'FileSystemWatcher' could not be found (are you missing a using directive or an assembly reference?) What am I doing wrong (I'm sure it is something incredibly simple).


Solution

  • Because FileSystemWatcher is not included in the version of .NET used for Windows 8 apps. If it was supported you would see ".NET for Windows Store apps, Supported in: Windows 8" in the Version Information section of the MSDN page. Contrast this with BinaryReader which is available.

    The Windows.Storage namespace has the APIs for file system access in Windows 8 apps.