0

I have created an app that will open a File from a server in Word. I am truying to use filewatcher to determine when to post changed word document back to server. But Microsoft changes the filenames and I have no way to know which temp file name corresponds with my original filename.

Any help would be greatly appreciated.

 FileSystemWatcher watcher = new FileSystemWatcher();
 watcher.Path = path;
 watcher.Filter = "*.*";
 watcher.Changed += new FileSystemEventHandler(OnChanged);
 watcher.Deleted += new FileSystemEventHandler(OnChanged);

 watcher.Created += new FileSystemEventHandler(OnChanged);
 watcher.EnableRaisingEvents = true;

What I am actually looking for is a way to edit files through my application in Word. Kind of like Sharepoint Online.

Bartvandee
  • 289
  • 3
  • 19
  • I'm unclear on what's happening here. If you just open the file from the server directly, Word will lock the file, and you won't be able to post changes until the user closes the file in Word. If you copy it to the local system yourself, yes there are temp files, but you should only care about the original. Users often have good reasons for not uploading a file with partial changes. – Joel Coehoorn Sep 10 '18 at 13:26
  • Possible duplicate of [C#: Using FileSystemWatcher to watch for changes to files](https://stackoverflow.com/questions/3967658/c-using-filesystemwatcher-to-watch-for-changes-to-files) – Adam Ostrožlík Sep 10 '18 at 13:28
  • think about set filter to extension of your file observed – Antoine V Sep 10 '18 at 13:29
  • @JoelCoehoorn Since the user does not have direct access to the WebDav I need to download and save it to the local file system. I then open the document. I can still get the original file but don't have a method of knowing when the original file is saved. – Bartvandee Sep 11 '18 at 06:00
  • Sure you do. LastModifiedDate attribute on the file you just downloaded. – Joel Coehoorn Sep 11 '18 at 14:06
  • Word does not overwrite files, that's too risky. It *renames* the file after saving it. So you need the Renamed event to see that happening. – Hans Passant Sep 14 '18 at 12:52

1 Answers1

0

I made some adjustments to my app after a comment by @JoelCoehoorn about opening file directly from server. This works perfect :) So I have no more need for the FileWatcher. Thank you @JoelCoehoorn

Bartvandee
  • 289
  • 3
  • 19