locked
AddIn: DocumentSaved Event not firing for web site projects RRS feed

  • Question

  • Visual Studio 2010 C# (not SP1)

    I want to run a function on a file when a document is saved (within a web site, not a normal C# project), but for some reason the event is not firing for web site solutions. It works as expected on normal projects.

    Here is my code so far:

        DocumentEvents docEvents;
        Events events;
    
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
    
            events = _applicationObject.Events;
            docEvents = events.DocumentEvents;
    
            docEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(docEvents_DocumentSaved);
    
        }
    
        void docEvents_DocumentSaved(Document document)
        {
            //do something here (doesn't reach this for a web site or single file)
        }
    

    Interestingly, if I first load in a normal project and then a website it works fine. Why does it not work if I just open a web site?

    Any help would be appreciated.

    Thursday, September 27, 2012 11:22 AM

All replies

  • Hi LMTim,

    I can't reproduce you issue. It worked fine in my computer.

    If we debug your add-in, can the function docEvents_DocumentSaved be called?

    Please post the steps to reproduce your issue.

    Thanks,

    Ego


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Friday, September 28, 2012 7:25 AM
  • Thanks for taking a look, Ego

    The exact steps are as follows

      • Create a new add in with the code in my original post
      • Place a breakpoint in the DocumentSaved handler and press run
      • A new visual studio instance is loaded, open a normal c# console application
      • Save a document
      • Event is fired, breakpoint is hit
      • Close the visual studio window to stop debugging
      • Run the add in again, this time opening a website (File->Open->Web Site)
      • Save a document
      • Event is not fired and breakpoint is not hit

    Hope this helps

    OS Name Microsoft Windows 7 Home Premium
    Version 6.1.7601 Service Pack 1 Build 7601

    IDE Microsoft Visual Studio 2010 Professional

    Friday, September 28, 2012 9:24 AM