Enable preview in Visual Studio 2012 after Update 1

tabsandwindows

After installing Visual Studio 2012 Update 1, my Visual Studio stopped opening files in preview mode when I clicked them in the Solution Explorer. This setting seems to have changed with the installation of Update 1. To re-enable opening files clicked (once) in the Solution Explorer in Preview mode, go to ‘Tools’ – ‘Options’ – ‘Environment’ – ‘Tabs and Windows’.

There, check the box under ‘Preview Tab’ – ‘Single-click opens files in the preview tab in:’ – ‘Solution Explorer (Alt + click to avoid previewing)’.

Hope this helps

EDIT:
This is a lot easier: the ‘Preview Selected Items’ button in the Solution Explorer toolbar:

Preview Selected Items button

By |December 2nd, 2012|HowTo, Tip, VS2012|0 Comments

How To: Create an ActionLink with a Twitter Bootstrap icon in MVC4

Twitter Bootstrap is a… “Sleek, intuitive, and powerful front-end framework for faster and easier web development.” One of the nice things in Bootstrap is you can use icons from Glyphicons. To use these, you can simply use this markup <i class=”icon-fire”></i> get a nice fire icon (fire ).
Translating this into an ActionLink styled as a button in an MVC4 application would look something like the following:

@Html.ActionLink("<i class="icon-fire"></i> Invent fire", "fire", new { @class = "btn" })

Unfortunately, this renders as follows:

encoded

The reason this is not rendered correctly is because Html.ActionLink HtmlEncodes the text you pass in the actionLink parameter. You can check this by opening the System.Web.Mvc assembly in your disassembler of choice, and having a look at the GenerateLinkInternal method on the HtmlHelper class. It HtmlEncodes the linkText, and doesn’t have any option to have it not do that. To solve this, I wrote an extension method called NoEncodeActionLink, looking like this:

public static IHtmlString NoEncodeActionLink(this HtmlHelper htmlHelper, string linkText, string action, object htmlAttributes) 
{ 
    TagBuilder builder; 
    UrlHelper urlHelper; 
    urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); 
    builder = new TagBuilder("a"); 
    builder.InnerHtml = linkText; 
    builder.Attributes["href"] = urlHelper.Action(action); 
    builder.MergeAttributes(new RouteValueDictionary(htmlAttributes)); 
    return MvcHtmlString.Create(builder.ToString());
}

Calling the new overload (don’t forget to add a using statement to the namespace holding the extension method), the linkText parameter is not HtmlEncoded, which means the ActionLink now renders fine, including the icon (and the button style):

unencoded

Hope this helps.

By |November 7th, 2012|.Net, Development, HowTo, MVC4|3 Comments

TIP: “Paste XML as Classes” in Visual Studio 2012

pastespecial

In the past, when you had some XML document that you wanted to translate into classes we had to create / generate a schema based on the XML file. Next, we had to generate a class based on the schema with an external tool. Not all too user friendly and somewhat time consuming.

In Visual Studio 2012 you copy the XML you want to create a class/classes for, place the cursor in a class file on the location you want the code to be added and select the following menu items: Edit – Paste Special – Paste XML as Classes. And you’re done! Just like that…

If you want to try real quick, there’s a sample XML file (books.xml) available here.

EDIT
The feature is .NET Framework 4.5 specific. Taken from this MSDN article ‘Generating Data Type Classes from XML‘:
“.NET Framework 4.5 includes a new feature to generate data type classes from XML.

Microsoft Touch Mouse, Visual Studio (2012) and scrolling

My Microsoft Touch Mouse stopped scrolling in Visual Studio on my Windows 8 machine some time ago. Because this kills productivity, I wanted to fix the problem. After trying some things I found that the problem only occurred when I ran Visual Studio as Administrator. Searching a bit further I found this bug to be added to Microsoft Connect. I found a workaround for the problem:

  • Go to the location where you have Microsoft Mouse and Keyboard Center installed
  • Open up the properties of ipoint.exe
  • Set it to Run as Administrator
  • Kill and restart ipoint.exe (or restart the machine)
  • Welcome back scrolling in Visual Studio…!

Hope this helps

HowTo: Have Visual Studio always run as administrator on Windows 8

In my previous post I wanted my Visual Studio to ‘Run as Administrator’ on my Windows 8 machine. I only managed to get this working for the pinned taskbar icon and not for items in the jumplist or for items you open by double clicking them. The solution to check the box ‘Run as Administrator’ on the compatibility tab of the file properties for devenv.exe was not a solution, because there is no more Compatibility tab in Windows 8 :).
But there is a way to have devenv.exe always ‘Run as Administrator’. Here’s how:

  • Right click devenv.exe en select Troubleshoot compatibility (first picture)
  • Select the option ‘Troubleshoot program’ after the wizard has finished detecting issues
  • Choose the ‘The program requires additional permissions’ option (second picture). The wizard will apply the ‘Run as Administrator’ setting to devenv.exe
  • Click ‘Test the program…’ (third picture – the wizard requires this) and close the wizard
  • Enjoy!

 

Picture 1  Picture 2  Picture 3

Unable to access the IIS metabase

The Web Application Project SomeWebProject is configured to use IIS.  Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.I opened a solution in Visual Studio 2012 on my laptop running Windows 8, when I was presented with the error “The Web Application Project SomeWebProject is configured to use IIS.  Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.” The user I was logged in with was a local administrator and was able to open up and use IIS Manager, but still I was presented with this error. The solution to this is simple: start your Visual Studio with ‘Run as Administrator’. You can do this by right clicking the shortcut and selecting ‘Run as Administrator’.

TIP:
To always have your Visual Studio open with ‘Run as Administrator’, please follow these steps:
– right click the shortcut you are used to use
– bring up its properties
– click ‘Advanced…’ on the ‘Shortcut’ tab
– check the box ‘Run as administrator’ (see image below)
– close the windows with ‘OK’

Somehow I felt like this was default behavior on my Win7 VS2010 install, but it might be I set up the shortcut for it there too…

Coming home

Just a small post today: as of September first I joined Betabit (site is in Dutch).
After having had several employers in the last few years, this feels like coming home.

On our way to do nice things…!

By |September 21st, 2012|Personal|0 Comments

Ajax Control Toolkit Calendar doesn’t close when clicking outside the calendar

Just a quick one: if you have a textbox with a Calendar (extender) from the Ajax Control Toolkit and an associated PopupButtonID which is an image, the calendar won’t close when you click outside the popup. Use an input type=”image”or an ImageButton to solve this problem.

Hope this helps.

Documents.Open returns null, running Word automation under ASP.NET on x64

When building an ASPapplication that generates Word documents,  it was working fine on the local machine. A windows XP installation with Office 2007. When we deployed it to windows 2008 (64 bit) and Word 2007 we saw that Documents.Open returned null. Other than this, there are no exceptions.

The code that returned the error (simplified):

Application app = new Application();
Document doc = app.Documents.Open(ref name);

As it turns out, a 64 bit system stores temporary files in “C:WindowsSysWOW64configsystemprofileDesktop” folder.

The solution: create a new directory called “Desktop” inside “C:WindowsSysWOW64configsystemprofile”

Hope this helps.

Unhandled exception installing SQL Server 2008 R2 on a Windows XP / Windows 7 machine

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. (C:Documents and SettingsBoschRLocal SettingsApplication DataMicrosoft_CorporationLandingPage.exe_StrongName_ryspccglaxmt4nhllj5z3thycltsvyyx10.0.0.0user.config line 5) ---> System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.When installing SQL Server 2008 R2 on a Windows XP (or, according to the comments, Windows 7) development machine that has been around for quite some time, I got an error stating an unhandled exception occured in the application (see image). The error showed up directly upon startup and read:

An error occurred creating the configuration section handler for userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings: Could not load file or assembly ‘System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ or one of its dependencies.

Repairing the .NET 4.0 framework didn’t solve the issue. Neither did removing all SQL stuff through ‘Add or Remove Programs’. Looking into the error a bit further…

 The system cannot find the file specified. (C:Documents and Settings_USERNAME_Local SettingsApplication DataMicrosoft_CorporationLandingPage.exe_StrongName_ryspccglaxmt4nhllj5z3thycltsvyyx10.0.0.0user.config line 5) —> System.IO.FileNotFoundException: Could not load file or assembly ‘System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ or one of its dependencies. The system cannot find the file specified.

 So the problem probably wasn’t that System.dll couldn’t be found, but some user.config file for the landingpage executable. The solution is as simple as it is radical: remove the entire (temporary) folder ‘C:Documents and Settings_USERNAME_Local SettingsApplication DataMicrosoft_Corporation’ (where USERNAME_ is, of course, the current username). After this the setup should start up without any problems.

By |January 27th, 2012|.Net, Development, Error, SQL, Work|1 Comment