簡體   English   中英

無法在Visual Studio 2012中使用FileSystemWatcher

[英]Can't use FileSystemWatcher in Visual Studio 2012

我是Visual Studio和C#的新手。 我曾經使用過XCode和Objective-C,但現在嘗試編寫Windows 8應用程序。 我試圖在用戶單擊我的應用程序中的按鈕時設置FileSystemWatcher ,但是由於某些原因,Visual Studio拒絕承認我可以執行此操作並引發錯誤。 這是我寫的示例:

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();
        }
    }
}

FileSystemWatcher都用紅色下划線兩次,並帶有錯誤: Error 1 The type or namespace name 'FileSystemWatcher' could not be found (are you missing a using directive or an assembly reference?)我在做什么錯了(我確定是的)是一件非常簡單的事情)。

因為Windows 8應用程序使用的.NET版本不包括FileSystemWatcher 如果支持,則將在MSDN頁面的 “版本信息”部分中看到“ .NET for Windows應用商店應用程序,受支持:Windows 8”。 將其與可用的 BinaryReader進行對比。

Windows.Storage 命名空間具有用於Windows 8應用程序中文件系統訪問的API。

要在創建,修改或刪除文件或文件夾時得到通知,可以使用Windows.Storage.Search.StorageFolderQueryResultWindows.Storage.Search.StorageFileQueryResult類以及ContentsChanged事件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM