Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SharePoint 2010 Debug Client Side Code Hooking IE

Posted on 2012-03-23
10
Medium Priority
?
377 Views
Last Modified: 2013-11-26
I need to have the click of a word document from within IE breakpoint within some VSTO code.  In the past I had done something similar with finding the running IE process and associating that process with some code and indeed was able to break point within the code triggered by clicking a link in IE.

However,  the details of this technique and its applicability for breaking within a VSTO word add in is unclear.

Please advise / point to article(s).

Thanks.
0
Comment
Question by:Howard Bash
  • 3
  • 3
10 Comments
 
LVL 15

Expert Comment

by:colly92002
ID: 37756889
I'm not clear as to what you want to do here.   When you click on a link to a Word doc in a document library, you are actually running some Sharepoint javascript code which checkes the document type, then checks the status (checked in, approved etc) and then if applciavble gives you teh option to check out the file and edit it.  At this point, Word has not been launched, so VSTO is not rellevant.

Once this has processed, Word is launched, and you  therefore could break the VSTO code here.

If you are running Sharepoint in IE on your dev machine, then Word should have your VSTO code deployed to it here, so add this in the ThisAddIn.cs  class of the VSTO code:
System.Diagnostics.Debugger.Break();

If it is a problem with a deployed version of the VSTO, then the above line will break the code, and you should be able to attach to the process in the normal way (although I have never tried this).
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 37756911
When the link is clicked and word eventually is launched,  I want word launched but to breakpoint in code within my VSO Word ribbon add in load event.  So,  are you suggesting I put the System.Diagnostics.Debugger.Break() in my ribbon load event and that will cause it to launch VS2010 and break at that point?

Also,  I find that once I run the add in in the IDE,  it is installed without running any install code.  I can go into add/remove programs and uninstall and remove it from Word Com-addins and once I run the code in the IDE it is re-installed.  This seems to me to be a bug.
0
 
LVL 15

Assisted Solution

by:colly92002
colly92002 earned 2000 total points
ID: 37756932
Yes add it to the code and run on your dev machine and it should lauch VS.

Your VSTO addin will sit in Word until you remove it and this is why I was confiused, as a break in your code should jump to the debugger if it is open and you have just debugged it (which installs it on the dev machine).  This catches out everytbody I think (it certainly did to me when I first created one!).  You should remove it in code on your close event (ThisAddIn_Shutdown).  IIRC the MS examples all do this.  I also check at load and remove it there if it exists.

I've just looked at one I created which adds a menu bar (this is Word 2003 but should still relevant although teh events might have changed) and I have a method for removing it, and another for creating it, and I call them on this events:
private void App_DocChangeEvent()
        {
            RemoveMenubar();
            AddMenuBar();
        }
        private void App_DocOpenEvent(Word.Document Doc)
        {
            RemoveMenubar();
            AddMenuBar();
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // Remove the menu bar
            RemoveMenubar();

        }

Open in new window

0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 1

Author Comment

by:Howard Bash
ID: 37757123
The word ribbon add in code does not have document open or document change.  Also, I'm not catching why you'd put code in an add-in that removes itself from the add-ins when the document/word closes.  Wouldn't that require reinstalling it next time  you would want to use it?
0
 
LVL 15

Accepted Solution

by:
colly92002 earned 2000 total points
ID: 37757684
As I said the example I give is from an office 2003 project - it may have changed completely!

When you add a customisation to the menu in 2003 (and I am presuming the Ribbon in 2010) this sits in your local customisation cache (Normal.dot).  The actual VSTO code is in a dll hooked up in the registry.  Because you are on a dev machine, the dll is always available, and when it runs it the first thing it does is adds the customisations to the menu   and this is recorded in normal.dot.  If you don't remove it when you exit, and check before you add it again on startup (in case the previous run crashed out rather than cleaning up) the next time you run it you will get two menus etc.  That is certainly how it works in 2003. It is possible that this has been completely changed in 2010, I don't know, so please don't le me confuse you, it just seems that the behaviour you describe seems reasonable to me.

Just try the walkthrough here:
http://msdn.microsoft.com/en-US/library/aa942955%28v=vs.80%29.aspx
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 37793111
The suggested URL doesn't seem to address how to hook into the code in debug.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question