3

I am developing a windows application to compliment our web application, it is a small document management system like dropbox, I have to automatically sync the files on its closure, for e.g. if a .dwg (AUTOCAD) file is opened through my application, an event should trigger on that particular file's closure, is it possible with Filesystemwatcher class? The problem is that in AUTOCAD the file is opened as tabs, I know we can do this in MS Office applications with interop library. How we can do the same for applications like AUTOCAD and Photoshop?

Ben
  • 2,433
  • 5
  • 39
  • 69
midhun
  • 39
  • 4

3 Answers3

3

Try using FileSystemWatcher's Changed event. Something like that:

    FileSystemWatcher watcher = new FileSystemWatcher();
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
       | NotifyFilters.FileName;
    // Only watch AutoCAD files.
    watcher.Filter = "*.dwg";
    watcher.Changed += new FileSystemEventHandler(OnChanged);
cyberj0g
  • 3,707
  • 1
  • 19
  • 34
  • but can we track on the exact moment when the file is closed? – midhun Jul 14 '15 at 07:07
  • Maybe AutoCAD have some specific behavior when closing the file, for example deletion of associated scratch files from the same folder, like MS Office? If that's not the case I cannot think of a way to do it other than developing special AutoCAD plugin. – cyberj0g Jul 14 '15 at 07:28
0

Inside AutoCAD you can also develop plugin (just like for MS Office) using its .NET API.

There is a DocumentCollection.DocumentDestroyed event that is triggered when you close a document (saving or not): http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer's%20Guide/index.html?url=WS1a9193826455f5ff2566ffd511ff6f8c7ca-4875.htm

Or you can use the Database.SaveComplete event

Anyway, this will need an app running with AutoCAD, if you track the files (FileSystemWatcher) should be easier.

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
0

For AutoCAD use FileSystemWatcher to watch for the .dwl file being created and deleted. That file has the metadata regarding who opened the file and when. It is deleted when the file is closed and the lock is released. Later versions have a .dwl2 file as well. Things to watch - it can get left behind if AutoCAD crashes.

I don't recall if it is created when a file is opened read-only but there is no need to sync it in that case anyway.

CAD bloke
  • 8,578
  • 7
  • 65
  • 114