Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Problema FileSystemWatcher

    Salve ragazzi, sto usando la classe FileSystemWatcher, per tenere sotto
    controllo le azioni che vengono eseguite sul file .doc, però ho un
    problema, se apro un file doc che si trova sul desktop, stranamente
    l'evento Changed non viene invocato, posto di seguito il codice
    relativo, con la speranza che qualcuno possa aiutarmi

    codice:
    static void Main(string[] args)
            {
    
                watcher.Path = "C:\\F:\\";
    
    
                watcher.NotifyFilter = NotifyFilters.LastAccess |
    NotifyFilters.LastWrite
                   | NotifyFilters.FileName | NotifyFilters.DirectoryName;
                // Only watch text files.
                watcher.Filter = "*.doc";
                watcher.IncludeSubdirectories = true;
    
                // Add event handlers.
                watcher.Changed += new FileSystemEventHandler(OnChanged);
                watcher.Created += new FileSystemEventHandler(OnChanged);
                watcher.Deleted += new FileSystemEventHandler(OnChanged);
                watcher.Renamed += new RenamedEventHandler(OnRenamed);
    
                // Begin watching.
                watcher.EnableRaisingEvents = true;
    
                // Wait for the user to quit the program.
                Console.WriteLine("Press \'q\' to quit the sample.");
                while (Console.Read() != 'q') ;
            }
    
            // Define the event handlers.
            private static void OnChanged(object source,
    FileSystemEventArgs e)
            {
                // Specify what is done when a file is changed, created, or
    deleted.
                Console.WriteLine("File: " + e.FullPath + " " +
    e.ChangeType);
    
            }
    
    
            private static void OnRenamed(object source, RenamedEventArgs
    e)
            {
                // Specify what is done when a file is renamed.
                Console.WriteLine("File: {0} renamed to {1}",
    e.OldFullPath, e.FullPath);
            }

  2. #2
    Semplice.
    Lui guarda solo la cartella c:\ e non le sottodirectory VVoVe:

  3. #3
    Con questa istruzione watcher.IncludeSubdirectories = true;
    dovrei includere tutte le sottocartelle

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.