filesystemwatcher

Filesystem watcher and large files

…衆ロ難τιáo~ 提交于 2019-11-26 22:21:59
问题 var fsw = new FileSystemWatcher(sPath, "*.PPF"); fsw.NotifyFilter = NotifyFilters.FileName; fsw.IncludeSubdirectories = true; fsw.Created += FswCreated; fsw.EnableRaisingEvents = true; static void FswCreated(object sender, FileSystemEventArgs e) { string sFile = e.FullPath; string[] arrLines = File.ReadAllLines(sFile); } this fails with large files, because the process is not finnished with writing the file. The file is copied via the Network, so i dont know the size of the file. What kind of

How do you monitor file access and changes on a file server by user name?

℡╲_俬逩灬. 提交于 2019-11-26 21:53:40
问题 I was asked to find a way to monitor changes (modification, renaming, deletion, moving) of files in specific folders on the company's shared file server (simple windows shared directory). I wrote a simple app in C# that uses FileSystemWatcher to monitor these changes and notify a particular email address of them. What I'd like to know now is how to find out the name/IP of the user/computer who made these changes. Any ideas? As an alternative to writing my own software, are there any good

FileSystemWatcher events raising twice despite taking measures against it

妖精的绣舞 提交于 2019-11-26 21:41:56
问题 I've browsed quite a few threads on here and on other sites for solutions to this problem. Here's my FileMonitor class: class FileMonitor { public FileMonitor(String path) { try { var watcher = new FileSystemWatcher() { Path = path, IncludeSubdirectories = true, InternalBufferSize = 65536, EnableRaisingEvents = true }; watcher.Changed += new FileSystemEventHandler(OnFileChanged); watcher.Created += new FileSystemEventHandler(OnFileCreated); watcher.Deleted += new FileSystemEventHandler

FileSystemWatcher Fails to access network drive

你。 提交于 2019-11-26 21:06:14
I am trying to run a file watcher over some server path using windows service. I am using my windows login credential to run the service, and am able to access this "someServerPath" from my login. But when I do that from the FileSystemWatcher it throws: The directory name \someServerPath is invalid" exception. var fileWatcher = new FileSystemWatcher(GetServerPath()) { NotifyFilter=(NotifyFilters.LastWrite|NotifyFilters.FileName), EnableRaisingEvents=true, IncludeSubdirectories=true }; public static string GetServerPath() { return string.Format(@"\\{0}", FileServer1); } Can anyone please help

Use FileSystemWatcher on a single file in C#

旧巷老猫 提交于 2019-11-26 20:51:36
问题 When i try to set the watcher path to a single file like so: watcher.Path = filePath1; I get the error: The directory name C:\Cromos 3.0\repository\diagnostics\dwm01_2011_06_13__09_03.LXD is invalid. Can you only set the path to a folder directory? 回答1: Your error is setting the Path property with a full filename watcher.Path = Path.GetDirectoryName(filePath1); watcher.Filter = Path.GetFileName(filePath1); should work. Not related to your proper question, but, of course, as stated in below

How to monitor a complete directory tree for changes in Linux?

≯℡__Kan透↙ 提交于 2019-11-26 19:16:53
问题 How can I monitor a whole directory tree for changes in Linux ( ext3 file system)? Currently the directory contains about half a million files in about 3,000 subdirectories , organized in three directory levels. Those are mostly small files (< 1kb, some few up to 100 kb). It's a sort of queue and I need to know when files are being created, deleted or their content modified within 5-10 seconds of that happening. I know there is inotify and sorts, but AFAIK they only monitor a single directory

Find out username(who) modified file in C#

此生再无相见时 提交于 2019-11-26 17:56:42
I am using a FileSystemWatcher to monitor a folder. But when there is some event happening in the directory, I don't know how to search who made a impact on that file. I tried to use EventLog. It just couldn't work. Is there another way to do it? I cant remember where I found this code but its an alternative to using pInvoke which I think is a bit overkill for this task. Use the FileSystemWatcher to watch the folder and when an event fires you can work out which user made the file change using this code: private string GetSpecificFileProperties(string file, params int[] indexes) { string

FileSystemWatcher to watch UNC path

ぐ巨炮叔叔 提交于 2019-11-26 17:39:03
问题 There are no shortage of questions on this topic, but I'm still having trouble. Here is my situation. I've got a service that I need to watch a path that is specified in the config file. It works great when I used a local drive. However, when I change it to something like \\server2\secondary\temp\watch_folder the service does not start. The error in the log is The directory name \\server2\secondary\temp\watch_folder is invalid. If I copy that directly into Windows Explorer the folder opens

Detect File Read in C#

亡梦爱人 提交于 2019-11-26 17:13:48
问题 I'm using FileSystemWatcher to check when a file is modified or deleted, but I'm wondering if there is any way to check when a file is read by another application. Example: I have the file C:\test.txt on my harddrive and am watching it using FileSystemWatcher. Another program (not under my control) goes to read that file; I would like to catch that event and, if possible, check what program is reading the file then modify the contents of the file accordingly. 回答1: It sounds like you want to

Does FileSystemWatcher create its own thread?

北城余情 提交于 2019-11-26 16:51:16
问题 I want this work to be done in a different thread but do i have to create a thread or does it do all the work on different threads? Like: Thread fileThread = new Thread(() => { FileWatcher = new FileSystemWatcher(); FileWatcher.Created += OnFileEvent; FileWatcher.Deleted += OnFileEvent; FileWatcher.Renamed += OnRenameEvent; FileWatcher.EnableRaisingEvents = true; }); fileThread.Start(); 回答1: You don't have to create a thread. The events will be called on a separate thread automatically. 来源: