From VSIP Diaries….

Q. How to get notifications in editor when the file is modified outside of the editor?


A. You ask why care about it. Well if you care about being notified when the file changed on disk outside of Visual Studio. This gives you the opportunity to update the file contents if the file is open in the IDE. If you are implementing a project system and editors you would want to track change events from the file system.

            Visual Studio provides a mechanism to hook into these events by implementing the IVsFileChangeEx interface. This is exposed to the Visual Studio Packages via the SVsFileChangeEx service. The clients need to implement IVsFileChangeEvents interface and register it to be called back. Clients can register to be called back for directory changes in addition to file changes as well. Here is what clients need to do:

§          Implement IVsFileChangeEvents

§          Query for SVsFileChangeEx service and obtain IVsFileChangeEx interface

§          If interested in directory changes call IVsFileChangeEx::AdviseDirChange passing in an implementation of IVsFileChangeEvents

§          If interested in file changes call IVsFileChangeEx::AdviseFileChange passing in an implementation of IVsFileChangeEvents.


Using SVsFileChangeEx service it is also possible to ignore file changes and update changes to a file without getting the notifications.

Defined in vsshell.idl


Q. How to tell the project type based on hierarchy?


A. Many times you while walking the solution hierarchy you may want to find out what project type you have currently selected. While there are other in-direct ways of getting to the project type of the selected hierarchy you can definitively get to it by using the IPersist interface that all hierarchies implement.  Using IPersist you can get the GUID for the project factory. Here is what you need to do:

§          QueryInterface for IPersist on IVsHierarchy

§          Call IPersist::GetClassID


Hope that was helpful.



Dr. eX



Comments (0)

Skip to main content