by Pieter Brinkman
25. February 2010 09:58
Create a Visual Studio add-in with contextmenu and selected text as input
When working with a new way of storing settings in a database. I was frustrated how much work it was to check the value of setting from code. So I deceided to make my life a bit easier by creating a VS2008 contextmenu add-in. With this add-in I can select text within VS and use the value of the selected text within the add-in popup. The hardest part was figuring out how to create a contextmenu and how to use the selected text as input value.
In this blogpost I will show how to create a Visual Studio contextmenu add-in and pass the selected text to the pop-up. I’m not going to explain how to create an add-in you can easily find articles about this on MSDN or blogs (just try Google).
Now let’s get started. Create an new Visual Studio add-in project and add the following code to the OnConnetion Method within the Connect.cs. This code will insert add the contextmenu.
[code:c#]
_applicationObject = (DTE2)application;
CommandBars cBars = (CommandBars)_applicationObject.CommandBars;
CommandBar editorCommandBar = (CommandBar)cBars["Editor Context Menus"];
CommandBarPopup editPopUp = (CommandBarPopup)editorCommandBar.Controls["Code Window"];
Command command = commands.AddNamedCommand2(_addInInstance,
"GetSetting", "Bekijk Setting", "Executes the command for test", true, 733, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText,
vsCommandControlType.vsCommandControlTypeButton);
[/code]
Then to get the selected text I use the following method within the Exec of the Connect.cs and pass the selected text (return value) to a property of a Windows Form pop-up.
[code:c#]
private string GetSelection()
{
string setting =
"";
//Check active document
if (_applicationObject.ActiveDocument != null)
{
//Get active document
TextDocument objTextDocument = (TextDocument)_applicationObject.ActiveDocument.Object("");
TextSelection objTextSelection = objTextDocument.Selection;
if (!String.IsNullOrEmpty(objTextSelection.Text))
{
//Get selected text
setting = objTextSelection.Text;
}
}
return setting;
}
[/code]
Hope it helps.
Cheers,
Pieter
by Pieter Brinkman
20. August 2009 02:53
When deploying a Silverlight application we ran into problems a WCF web-service, to find out what the problem was I wanted to invoke the method.
Microsoft shipped an application for invoking methods from your Windows PC (WCFtestclient.exe). The following steps explain how to use WCFtestclient.exe.
First startup Visual Studio 2008 Command Prompt. In the command prompt type wcftestclient, the application will startup.
Now we need to add the Service. Click File and Add Service.

Add the URL to your service in the pop-up and pres ok. The service will now add all methods from your service. You can add multiple service URLs.
Double click the method you want to invoke from the tree on the left pane. Enter the values that are required for the Invoke and press Invoke. The method will be invoked.

The right bottom pane will show the response. In my case this shows the Stack-trace because of the error. Normally this will show the web-service response (XML).
With the stack-trace I could located the error and fix it.
Hope this helps,
Pieter
by Pieter Brinkman
23. June 2009 03:49
The last few years I spend a lot of time working with Asp.Net AJAX. It all worked pretty good, the only downside is that you do not have control the generated HTML. With jQuery you can manipulate generated HTML. This HTML can be generated fully controlled with a ListView.
I'm a lazy programmer so the first thing I needed to do is fix jQuery Intellisense in VS2008. I found my information for doing this on Scott Gu's blog (jQuery Intellisense in Vs 2008). Everything worked great the only bad thing is that my computer needed a restart after installing a Visual Studio Patch...
Now the Intellisense is working the only thing I need to do is blog some nice examples of my work! ;-)
Cheers,
Pieter
by Mark
25. October 2007 11:34
Since a few days the newest version of Visual Studio has been released together with the new 3.5 .Net framework.
It contains tons of new features such as:
- Javascript Intellisense
- Multi-targeting support (.Net versions: 2.0, 2.0 and 3.5)
- Built in AJAX support (no need to install an extra package)
- New Html web designer (same as Expression Web) and improved CSS support
- Language improvements and LINQ
- Access to the .Net Framework Library source code (for more information read this post from Scott Guthrie
When you are a MSDN subscriber you can download it here. If not you can download the 90 day trial of the Team Suite edition here.
Be sure to read this post from Scott Guthrie’s blog
by Mark
13. August 2007 11:33
I
just tried to install the VS2008 SilverlightTools Alpha, but I
immediatly ran in to an error. The installation couldn’t start beacause
VS2008 was not installed. This suprised me because I just installed
thirty minutes before. A some searching I found out that I needed to
install the Visual Web Developer.
You can install this by running the VS2008 setup again an choose to add features. Now the Silverlight tools setup runs flawless.
by Mark
8. August 2007 11:32
I just installed VS 2008. The first time
that I tried to install it, the installation failed. Apparantly the
image (3 gb!) was corrupted and therefore the installation had troubles
with the cabinet files of the Document Explorer. I downloaded it again
and now the installation went flawless.
Tonight I made my first application. I created an rss reader (bases
on Scott Guthrie’s code) which uses LINQ. I think that LINQ is one of
the most important new features of the .Net 3.5 framework. It is an
feature which uses SQL like statements. I saw an demo of it from Erik
Meijer on the dutch DevDays and I immediatly loved it.
Now the next step is to try and expand the rss reader with Silverlight….