Solved

SharePoint 2010 Debug Client Side Code Hooking IE

Posted on 2012-03-23
10
325 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:hbash
  • 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:hbash
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 500 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:hbash
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 500 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:hbash
ID: 37793111
The suggested URL doesn't seem to address how to hook into the code in debug.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now