Search Results

Search found 70 results on 3 pages for 'filesystemwatcher'.

Page 1/3 | 1 2 3  | Next Page >

  • FileSystemWatcher keeping parent directory

    - by Henry Jackson
    I am using FileSystemWatcher to monitor a folder, and it seems to be preventing the folder's parent from being deleted. For example, I have the file structure: C:\Root\FolderToWatch\... with the FileSystemWatcher targeting FolderToWatch. While my program is running, if I go to Windows Explorer and try to delete Root, I get an error "Cannot delete Root: access is denied". However, if I delete FolderToWatch FIRST, I can then delete Root without incident. (Needless to say, if the FileSystemWatcher is not enabled, I have no problem deleting either folder.) What gives? Why does the FileSystemWatcher hang onto it's target's parent like that? How (if possible) can I stop this behavior? I would like the user to be able to freely move or delete directories in Windows Explorer.

    Read the article

  • Reusing Windows Picture and Fax Viewer process to load a new image from FileSystemWatcher

    - by Cory Larson
    So for an idea for my birthday party I'm setting up a photo booth. I've got software to remotely control the camera and all that, but I need to write a little application to monitor the folder where the pictures get saved and display them. Here's what I've got so far. The issue is that I don't want to launch a new Windows Photo Viewer process every time the FileSystemWatcher sees a new file, I just want to load the latest image into the current instance of the Windows Photo Viewer (or start a new one if one isn't running). class Program { static void Main(string[] args) { new Program().StartWatching(); } public void StartWatching() { FileSystemWatcher incoming = new FileSystemWatcher(); incoming.Path = @"G:\TempPhotos\"; incoming.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName; incoming.Filter = "*.jpg"; incoming.Created += new FileSystemEventHandler(ShowImage); incoming.EnableRaisingEvents = true; Console.WriteLine("Press \'q\' to quit."); while (Console.Read() != 'q') ; } private void ShowImage(object source, FileSystemEventArgs e) { string s1 = Environment.ExpandEnvironmentVariables("%windir%\\system32\\rundll32.exe "); string s2 = Environment.ExpandEnvironmentVariables("%windir%\\system32\\shimgvw.dll,ImageView_Fullscreen " + e.FullPath); Process.Start(s1, s2); Console.WriteLine("{0} : Image \"{0}\" at {1:t}.", e.ChangeType, e.FullPath, DateTime.Now); } } If you don't have a tried and true solution, a simple push in the right direction would be just as valuable. And FYI, this will be running on a 64-bit Windows 7 machine. Thanks!

    Read the article

  • FileSystemWatcher Changed event is raised twice

    - by user214707
    I have an application where I am looking for a text file and if there are any changes made to the file I am using the onchanged eventhandler to handle the event. I am using the notifyfilters.Lastwritetime but still the event is getting fired twice.Here is the code. public void Initialize() { FileSystemWatcher _fileWatcher = new FileSystemWatcher(); _fileWatcher.Path = "C:\\Folder"; _fileWatcher.NotifyFilter = NotifyFilters.LastWrite; _fileWatcher.Filter = "Version.txt"; _fileWatcher.Changed += new FileSystemEventHandler(OnChanged); _fileWatcher.EnableRaisingEvents = true; } private void OnChanged(object source, FileSystemEventArgs e) { ....... } I my case the Onchanged is called twice when I change the text file version.txt and save it.Please help.

    Read the article

  • Unit-test FileSystemWatcher.Error Event

    - by dotNetkow
    I'm trying to unit test a private method that I have attached to my FileSystemWatcher's Error event. MSDN says that this event "occurs when the internal buffer overflows." I've tried to cause a buffer overflow but have not been successful so far. The FileSystemWatcher's various properties are: fileWatcher.IncludeSubdirectories = false; fileWatcher.Filter = "*"; fileWatcher.NotifyFilter = (NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.Size); What is the best way of raising this event for the purpose of unit-testing?

    Read the article

  • FileSystemWatcher Changed event is raised twice

    - by user214707
    I have an application where I am looking for a text file and if there are any changes made to the file I am using the OnChanged eventhandler to handle the event. I am using the NotifyFilters.LastWriteTime but still the event is getting fired twice. Here is the code. public void Initialize() { FileSystemWatcher _fileWatcher = new FileSystemWatcher(); _fileWatcher.Path = "C:\\Folder"; _fileWatcher.NotifyFilter = NotifyFilters.LastWrite; _fileWatcher.Filter = "Version.txt"; _fileWatcher.Changed += new FileSystemEventHandler(OnChanged); _fileWatcher.EnableRaisingEvents = true; } private void OnChanged(object source, FileSystemEventArgs e) { ....... } In my case the OnChanged is called twice, when I change the text file version.txt and save it.

    Read the article

  • FileSystemWatcher event trigger problem(s)

    - by Bahadir Cambel
    It seems like , FileSystemWatcher triggers events more than once. Here is my settings ; watcher = new FileSystemWatcher(); watcher.Path = @"D:\testSpace"; watcher.InternalBufferSize = 1024*64; watcher.Deleted += Triggered; watcher.Changed += Triggered; watcher.Created += Triggered; watcher.Error += ErrorOccured; watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.IncludeSubdirectories = true; watcher.EnableRaisingEvents = true; One more thing that I found out that , new folder created event does not get triggered unless a new file created under the folder. do you guys know any work around for these issues ?

    Read the article

  • C#/WPF FileSystemWatcher on every extension on every path

    - by BlueMan
    I need FileSystemWatcher, that can observing same specific paths, and specific extensions. But the paths could by dozens, hundreds or maybe thousand (hope not :P), the same with extensions. The paths and ext are added by user. Creating hundreds of FileSystemWatcher it's not good idea, isn't it? So - how to do it? Is it possible to watch/observing every device (HDDs, SD flash, pendrives, etc.)? Will it be efficient? I don't think so... . Every changing Windows log file, scanning file by antyvirus program - it could realy slow down my program with SystemWatcher :(

    Read the article

  • FileSystemWatcher surpassing Active Directory restrictions

    - by DevexPP
    While experimenting with FileSystemWatcher, I've found out that it somehow surpasses Active Directory's restrictions to files and folders, and will raise change events with information about what has changed in files and folders that you don't even have access to. I have two questions about that: 1) Why does this happen ? 2) Is this a problem in the AD configuration ? how do I fix it ? 3) Is there any way to gather these files, or even create a FileSystemInfo of them to get more info about the files (not only the changes made on them) ? As far as I've tried, only the FileSystemWatcher immune to the restrictions, I can't run any other thing over it, here's a list of what I've tried: File.Exists Directory.Exists FileInfo instance on found files DirectoryInfo instance on found files File.Copy File.Delete

    Read the article

  • FileSystemWatcher.Changed fires immediately when Excel 2007 opens XLS file in compatibility mode

    - by Rick Mogstad
    We use a FileSystemWatcher to monitor documents opened from our Document Management system, and if the user saves the document, we ask if they would also like them updated in our system. We have a problem with XLS files in Excel 2007 (have not verified that the problem does not exist in 2003, but it only seems to be files that open in compatibility mode in 2007) where the Changed event fires immediately upon opening the file, and then once more upon closing the file, even if nothing has changed or the user chooses not to save upon closing. This same behavior does not exist when opening XLSX files. I wrote a test app to verify the behavior, which you can find at (http://www.just2guys.net/SOFiles/FSWExcel.zip). In the app, there is one FileSystemWatcher for each NotifyFilter type, so that it is apparent why the Changed event was fired. Any way you can think of to only prompt the user when the document is actually saved in some way by the user? I can start monitoring the file after Process.Start is called, which allows me to skip the message upon opening the document, but I still get one upon closing the document, even when nothing was changed.

    Read the article

  • FileSystemWatcher vs Polling to watch for changes

    - by Jon Tackabury
    I need to setup an application that watches for files being created in a folder (locally or on a network drive) and I was wondering if anyone has any thoughts on whether the FileSystemWatcher or polling on a timer would be the best option. I have used both methods in the past, but not extensively. Have you run into any issues (performance, reliability... etc) with either method? I know there isn't a "right way" to do this, I'm just looking opinions.

    Read the article

  • FileSystemWatcher running under impersonated user

    - by AdmSteck
    I have an c# winform application that runs under a local account but needs to monitor folders on a domain. I am using slightly modified code from here to copy the files and that works fine. Can similar code be used with the FileSystemWatcher set up impersonation so I can monitor a folder on a domain?

    Read the article

  • Watching a directory using FileSystemWatcher

    - by rashim
    Hello I'm watching a directory using FileSystemWatcher. When a file is created into that directory - my watcher grabs and transfers it to the network drive. My problem is that when a Microsoft-office file is opened, a temporary file is created in the watched directory. I can't find a way to ignore these files and also could not find when I should move these file to the network drive.

    Read the article

  • VB.NET FileSystemWatcher Multiple Change Events

    - by John
    Hi. I have the following code: Imports System.IO Public Class Blah Public Sub New() InitializeComponent() Dim watcher As New FileSystemWatcher("C:\") watcher.EnableRaisingEvents = True AddHandler watcher.Changed, AddressOf watcher_Changed End Sub Private Sub watcher_Changed(ByVal sender As Object, ByVal e As FileSystemEventArgs) MsgBox(e.FullPath) End Sub End Class When I run it and save changes to a file on my C drive, the code works great, except it executes the watcher_Changed() method four times. Any idea why? The changeType is "4" every time. Thanks.

    Read the article

  • FileSystemWatcher.WaitForChanged returns, but there is still a lock on the file

    - by SnOrfus
    I have a program that send a document to a pdf printer driver and that driver prints to a particular directory. After the print I want to attach the pdf to an e-mail (MailMessage) and send it off. Right now, I send the document to the printer (wich spawns a new process) and then call a FileSystemWatcher.WaitForChanged(WaitForChangedResult.Created) but when the object is created, it's still not done "printing" and the pdf printer still has a lock on it, throwing an error when I try to attach that file to an e-mail. I've considered a plain Thread.Sleep(2000) or whatever, but that's far less than ideal. I considered putting the attachment code in a try/catch block and looping on failure, but again, that's just bad news. I can't really think of an elegant solution.

    Read the article

  • Disabling FileSystemWatcher for specific updates?

    - by chaiguy
    Does anyone have any ideas how I can reliably disable a FileSystemWatcher object when my application makes changes to the files in the directory, so that I am only watching for external changes to the directory? I've tried setting EnableRaisingEvents to false immediately before performing a write and setting it back to true immediately after, but it seems this method is not reliable, and occasionally I still get the event firing. The only other thing I can think of is to wait a small amount of time after performing the write to let the OS finish up the modification of the directory before re-enabling the FSW, but that seems hackish and I don't like it. To add to the problem, the directory consists of potentially many files, the identities of which are beyond my knowledge and control, so I can't just wait for the event to fire for a specific file and then ignore it. There could be any number of FSW events firing after a single modification (because of the potentially many files getting updated).

    Read the article

  • Which filter of FileSystemWatcher do I need to use for finding new files

    - by BDotA
    So far I know that FileSystemWatcher can look into a folder and if any of the files inside that folder is changed,modifies,.etc... then we can handle it. But I am not sure which filter and event I should use in my scenario: Watch for a Folder, If a file is added to that folder, do XYZ ... So In my scenario I don't care if an existing file is changed,etc..those should be ignored...only do XYZ if and only if a new file has been added to that Folder... Which event and filter do you recommended for this scenario?

    Read the article

  • FileSystemWatcher Work is Done?

    - by Snowy
    I setup a FsWatcher on a local filesystem directory. I only want to know when files are added to the directory so they can be moved to another filesystem. I seem to be able to detect when the first file is in, but actually I want to know when all files from a given copy operation are done. If I used Windows Explorer to copy files from one directory to another, Explorer would tell me that there are n seconds left in the transfer, so while there is some activity for the begin-transfer and end-transfer for each file, it appears that there is something for the begin-transfer and end-transfer for all files. I wonder if there is something similar that I can do just with the .NET Framework. I would like to know when "all" files are in and not just a single file in a "transaction". If there is nothing baked in, maybe I should come up with some kind of waiting/countering in order to only do my activity when a job is "done". Not sure if I'm making 100% sense on this one, please anyone comment. Thanks.

    Read the article

  • Using FileSystemWatcher in detecting a xml file, using Linq in reading the xml file and prompt the results error "Root Element is Missing"

    - by GrayFullBuster
    My application is already working it can detect the xml file and prompt the content of the xml file but sometimes it will prompt "Root element is missing", and sometimes also it is okay but when I open the xml file, it is ok, it has contents on it. How to solve this issue. Here is the screenshot of the error: Here is the code: private void fileSystemWatcher_Created(object sender, System.IO.FileSystemEventArgs e) { string invoice = ""; using (var stream = System.IO.File.Open(e.FullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)) { var doc = System.Xml.Linq.XDocument.Load(stream); var transac = from r in doc.Descendants("Transaction") select new { InvoiceNumber = r.Element("InvoiceNumber").Value, }; foreach (var i in transac) { invoice = i.InvoiceNumber; } } MessageBox.Show(invoice); fileSystemWatcher.EnableRaisingEvents = false; } The error goes here var doc = System.Xml.Linq.XDocument.Load(stream);

    Read the article

  • FileSystemWatcher does not fire when using C++ std::ofstream

    - by Adam Haile
    I'm trying to add a log monitor to an in-house test utility for a windows service I'm working on. The service is written in C++ (win32) and the utility is in .NET (C#) The log monitor works for many other C++ apps I've written, but not for my service. The only main difference I can see is that the other apps use the older ::WriteFile() to output to the log, whereas in the service I'm using std::ofstream like this: std::ofstream logFile; logFile.open("C:\\mylog.log"); logFile << "Hello World!" << std::endl; logFile.flush(); From my utility I use FileSystemWatcher like this: FileSystemWatcher fsw = new FileSystemWatcher(@"C:\", "mylog.log"); fsw.Changed += new FileSystemEventHandler(fsw_Handler); fsw.EnableRaisingEvents = true; But for the service, it never gets any change events as the log is updated. I've found that any example code using FileSystemWatcher I've come across online has the same exact issue as well... But, I know the events should be available because other log monitor apps (like BareTail) work fine with the service log file. I'd rather get the C# code for the utility to just work so it works with anything, but if I have to change the logging code for the service I will. Does anyone see what's going wrong here?

    Read the article

  • Reactive Extensions vs FileSystemWatcher

    - by Joel Mueller
    One of the things that has long bugged me about the FileSystemWatcher is the way it fires multiple events for a single logical change to a file. I know why it happens, but I don't want to have to care - I just want to reparse the file once, not 4-6 times in a row. Ideally, there would be an event that only fires when a given file is done changing, rather than every step along the way. Over the years I've come up with various solutions to this problem, of varying degrees of ugliness. I thought Reactive Extensions would be the ultimate solution, but there's something I'm not doing right, and I'm hoping someone can point out my mistake. I have an extension method: public static IObservable<IEvent<FileSystemEventArgs>> GetChanged(this FileSystemWatcher that) { return Observable.FromEvent<FileSystemEventArgs>(that, "Changed"); } Ultimately, I would like to get one event per filename, within a given time period - so that four events in a row with a single filename are reduced to one event, but I don't lose anything if multiple files are modified at the same time. BufferWithTime sounds like the ideal solution. var bufferedChange = watcher.GetChanged() .Select(e => e.EventArgs.FullPath) .BufferWithTime(TimeSpan.FromSeconds(1)) .Where(e => e.Count > 0) .Select(e => e.Distinct()); When I subscribe to this observable, a single change to a monitored file triggers my subscription method four times in a row, which rather defeats the purpose. If I remove the Distinct() call, I see that each of the four calls contains two identical events - so there is some buffering going on. Increasing the TimeSpan passed to BufferWithTime seems to have no effect - I went as high as 20 seconds without any change in behavior. This is my first foray into Rx, so I'm probably missing something obvious. Am I doing it wrong? Is there a better approach? Thanks for any suggestions...

    Read the article

  • C# creating a queue to handle jobs triggered by FileSystemWatcher

    - by John S
    I have built a small tray app that will watch a folder and when a new file is added it runs a job. The job is to watch for video files and convert them to .mp4 using handBrakeCli. I have all this logic worked out. The problem I run into is that if there is more than one file I want it to queue the job til the prior one is complete. I am fairly new to c# and I am not sure of the best way to handle this. one idea is to create a queue somehow, a file to store the commands in order maybe, then execute the next one after the process is complete. We are dealing with large movie files here so it can take a while. I am doing this on a quad core with 8gb of RAM and it seems to generally take about 30mins to complete a full length movie. here is the code I have so far. there are some bits in here that are for future functionality so it refers to some classes that you wont see but it doesnt matter as they arent used here. any suggestions are welcome. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Diagnostics; using System.Threading; namespace movie_converter { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string hbCli; string cmd; string file; string strfilter = "*.*"; string[] filter = new string[3] { ".mkv", ".avi", ".wmv" }; //static list of types List<string> Ext = new List<string>(); //list of extensions to watch (dynamic) NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); private void SetUpTrayIcon() { notifyIcon.BalloonTipText = "Movie Converter is running minimized."; notifyIcon.BalloonTipTitle = "I'm still here"; notifyIcon.Text = "John's movie converter"; notifyIcon.Icon = new Icon(@"C:\\Users\\John\\Pictures\\appicon.ico"); notifyIcon.Click += new EventHandler(notifyIcon_Click); if (notifyIcon != null) { notifyIcon.Visible = true; notifyIcon.ShowBalloonTip(2000); } } private void Form_Resize(object sender, EventArgs e) { if (WindowState == FormWindowState.Minimized) { this.Hide(); SetUpTrayIcon(); } } private void notifyIcon_Click(object sender, EventArgs e) { this.Show(); this.WindowState = FormWindowState.Normal; notifyIcon.Visible = false; } public void Watcher() { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = textBox1.Text + "\\"; //path to watch watcher.Filter = strfilter; //what types to look for set to * and i will filter later as it cant accept an array watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName; //properties to look at watcher.IncludeSubdirectories = true; //scan subdirs watcher.Created += new FileSystemEventHandler(OnChanged); //TODO: make this only run if the files are of a certain type watcher.EnableRaisingEvents = true; // start the watcher } static bool IsFileLocked(FileInfo file) { FileStream stream = null; try { stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { //the file is unavailable because it is: //still being written to //or being processed by another thread //or does not exist (has already been processed) return true; } finally { if (stream != null) stream.Close(); } //file is not locked return false; } // Define the event handlers. private void OnChanged(object source, FileSystemEventArgs e) { string sFile = e.FullPath; //check that file is available FileInfo fileInfo = new FileInfo(sFile); while (IsFileLocked(fileInfo)) { Thread.Sleep(500); } if (System.Diagnostics.Process.GetProcessesByName("HandBrakeCLI").Length != 0) { Thread.Sleep(500); } else { //hbOptions hbCl = new hbOptions(); //hbCli = hbCl.HbCliOptions(); if (textBox3.Text != "") { hbCli = textBox3.Text.ToString(); } else { hbCli = "-e x264 -q 20 -B 160"; } string t = e.Name; string s = t.Substring(0, t.Length - 4); //TODO: fix this its not reliable file = e.FullPath; string opath = textBox1.Text.ToString(); cmd = "-i \"" + file + "\" -o \"" + opath + "\\" + s + ".mp4\" " + hbCli; try { for (int i = 0; i < Ext.Count(); i++) { if (e.Name.Contains(Ext[i])) { Process hb = new Process(); hb.StartInfo.FileName = "D:\\Apps\\Handbrake\\Install\\Handbrake\\HandBrakeCLI.exe"; hb.StartInfo.Arguments = cmd; notifyIcon.BalloonTipTitle = "Now Converting"; notifyIcon.BalloonTipText = file; notifyIcon.ShowBalloonTip(2000); hb.Start(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void button1_Click(object sender, EventArgs e) //ok button { //add each array item to the list for (int i = 0; i < filter.Count(); i++) { Ext.Add(filter[i]); } if (textBox1.Text != "" && textBox1.Text.Length > 2) { Watcher(); //call watcher to run } this.WindowState = FormWindowState.Minimized; } private void button2_Click(object sender, EventArgs e) //browse button { //broswe button DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { textBox1.Text = folderBrowserDialog1.SelectedPath; } } private void button3_Click(object sender, EventArgs e) //commands button { Process np = new Process(); np.StartInfo.FileName = "notepad.exe"; np.StartInfo.Arguments = "hbCLI.txt"; np.Start(); } private void button4_Click(object sender, EventArgs e) //options button { hbOptions options = new hbOptions(); options.ShowDialog(); } private void button5_Click(object sender, EventArgs e) //exit button { this.Close(); } private void Form1_Load(object sender, EventArgs e) { this.Resize += Form_Resize; } } }

    Read the article

  • Check if TIFF file is complete

    - by Davi
    I have a FileSystemWatcher monitoring a directory that receives TIF files from a scanning device. Its necessary to check if the scanning process is done and then read a multipage TIF file, otherwise, the FileSystemWatcher will raise the event before the file be fully scanned. I have something like: private void OnFileCreated(...) { while(IsFileLocked(path)) Thread.Sleep(time); // OK to read } This is what is happening: - Scanner creates the file - FileSystemWatcher detects the file, but its in use - Scanner reads the first page to the file - Scanner releases the file - My code leaves the while(FileInUse(path)) - My code reads the incomplete file (problem) - Scanner adds more pages to the file Let's say the scanner is scanning 100 pages, then, when "OK to read", the file will be incomplete (99 pages left). So, its necessary to know if the file is complete or not. Maybe waiting some time to see if the file is modified, but this time span can be up to hours, because the scanner can get idle scanning the same TIF. Other solution would be checking some flag in the TIF file that indicates that the file is not complete(I've looked for this but don't found anything).

    Read the article

  • Would watching a file for changes or redundantly querying that file be more efficient?

    - by badpanda
    I am wondering whether watching a file/directory for changes using the FileSystemWatcher class is extremely memory intensive. I am developing a desktop application in C# that will be running behind the scenes continuously on low-performance computers, and I need some way of checking to see if various files have changed. I can think of a few solutions: Watch the directories using FileSystemWatcher. Run a timed thread on an interval that goes through and manually checks this. Check manually every time the actionhandler thread runs (the program will occasionally do something, on an action). Any suggestions? Thanks! badPanda

    Read the article

  • FileSystemWatcher and System Out of Memory Exception

    - by Saurabh
    A little context There is a wpf based application which i left opened for 2-3 days without performing any activity throws out of memory exception , this is very Weird situation and does not happen all of the time. During this ideal activity , my application does nt perform any activity but just a file system watcher contineously watching a shared location , so i thought that would be a problem but i am not sure. Any suggestion is always welcomed.

    Read the article

1 2 3  | Next Page >