Priyank
Priyank

Reputation: 1174

Stop raising of create event for Filewatcher control for automatic generated temporary file of Original content

I am using filewatcher control in my winform app. I am performing uploading task by handling its events.

Now problem is that when I create any new document in directory(which is watched under FileWatcher control) uploading function starts and it uploads the document.(Which I want) but with creating new document in this directory system generates temporary file and it also uploaded to the server(Which I don't want).

As for example if I am creating a new word document named Microsoft Word Document.docx in xyz directory(This directory is watched under FileWatcher control) then system create another file like ~$w Microsoft Word Document.docx for that doc. and this both files are uploading to server.

Here I have take an example for a word file. Uploading content may be any(not fix).

Upvotes: 2

Views: 500

Answers (2)

Priyank
Priyank

Reputation: 1174

So I got a solution. I use a little validation before adding file in Queue for upload.

FileAttributes attr = System.IO.File.GetAttributes(e.FullPath);

FileInfo fi = new FileInfo(e.FullPath);     

if ((attr & FileAttributes.Hidden) == FileAttributes.Hidden || fi.Extension == ".tmp")
{
     return;
}

If I am getting file attribute hidden or its extension then I return from there.
Thats all :)

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1500555

Can you not just detect the temporary filename and ignore it? You may well find it has some attributes which make it obviously not-a-normal-file, or you could just spot the naming convention which Word uses. (How likely is it that you'll really want a file beginning with "$"?)

Upvotes: 2

Related Questions