Skip Back to an Earlier Change in Visual Studio

One of my favorite features in Visual Studio is Ctrl+- (hold down the Control key and press the minus key). Every time I press Ctrl+-, I skip back to the previous place I rested my cursor. I use this feature a lot when, after navigating through my code to investigate something, I want to get back to my start position so that I can make my actual change.

More

Posted by Peter Vogel on 02/16/20160 comments


Open an ASP.NET MVC Dialog Box with Backbone

I recently wrote a column on how to open a dialog box in an ASP.NET MVC application. In that column, I had the HTML for the dialog box dynamically generated at runtime from a Partial View and retrieved it by issuing an AJAX call from JavaScript running in the browser that called a method in my ASP.NET MVC Controller. To actually display the dialog I used the jQueryUI dialog add-in.

More

Posted by Peter Vogel on 02/05/20160 comments


Ensure HTML Forms Are Closed with the Using Block and BeginForm

In your Views, you can get the BeginForm helper to not only write out the open tag for your HTML form, but to write out your form's end tag. The trick is to call BeginForm as part of a Using block. The code looks like this, in Visual Basic:

@Using Html.BeginForm(...parms...)
  @Html.EditorFor(...
  ...rest of form...
End Using
More

Posted by Peter Vogel on 01/28/20160 comments


Hiding Methods from IntelliSense

Believe it or not, there are times when you have a member in your class that you don't want to appear in the class's IntelliSense lists.

In a column earlier this month I talked about how to have your class work with the .NET Framework support for formatting strings (things like "{0:G}," for example). By the time I had finished implementing this feature, my sample class had a method that no developer would ever call -- the method would only be called by .NET Framework components.

More

Posted by Peter Vogel on 01/21/20160 comments


Combining LINQ Queries (or, When to Call ToList)

LINQ with Entity Framework has become so common that, when I'm looking at a client's code I'm finding some pretty scary-looking LINQ queries running against Entity Framework. Since I'm a big fan of Really Obvious Code (ROC) -- ROC Rocks! -- I hate having to parse out these queries to try and figure out what the query is doing (and what's wrong with it).

More

Posted by Peter Vogel on 01/19/20160 comments


Seeing a File Twice in Visual Studio

You want to compare/view two parts of the same file at the same time. You have two choices for making this happen.

First, you can click on the divider bar at the top of the scroll bar on the right side of your editor window. Dragging that bar down divides your code window into two panes (one on top of the other), which you can scroll through independently.

More

Posted by Peter Vogel on 01/14/20160 comments


Configuring Entity Framework for Oracle

Oracle needs two NuGet packages in order to work with Entity Framework: one to use at design time and one to use at run time. You'll need to make sure both of these are installed (and it doesn't help that their names are so similar):

  • ODP.NET, Managed Entity Framework Driver
  • ODP.NET, Managed Driver
More

Posted by Peter Vogel on 01/05/20160 comments


Create Factory Functions in TypeScript for Creating Multiple Classes

In TypeScript, you can define a function that, when passed a set of parameters, creates and returns a correctly configured object. One of the parameters passed to the function must be the class of the object being created (I'll call that the "class parameter"). Normally, that means your factory function can only create a single kind of class but, by leveraging generics and interfaces, you can create functions that will create and configure a variety of classes.

More

Posted by Peter Vogel on 12/28/20150 comments


Warn Developers about Using Your Old Code

At least two or three times in my life, I've come back to old systems I'd worked on and realized that I now knew a better way of doing things. However, rather than just revise existing code, that "better way of doing things" required me to write a new method, property or class. When I released my new code out into the world, I wanted to tell other developers to stop using my old code and move to my new code. The best way to do that, I've decided, is to go back to the old code and decorate it with the Obsolete attribute.

More

Posted by Peter Vogel on 12/17/20150 comments


Wrapping Lines in Visual Studio

I was teaching Learning Tree's ASP.NET MVC course a few weeks back. The author of that course decided that having code lines extend past the right-hand edge of the code window wasn't a good idea if you're an instructor demoing some code. To eliminate those disappearing lines on the demo computer we use in the course, he turned on word-wrap for Visual Studio. This choice keeps all of the code on the screen by wrapping long lines of code back to the left hand margin.

More

Posted by Peter Vogel on 12/15/20150 comments


Create .zip Files from Code

If you've ever wanted to create a .zip file from your application, the System.IO.Compression.GZipStream will let you do it, assuming that you're comfortable with your file being in the industry-standard .gzip format (though I'm told you can swap in other compression schemes).

For this tip, I'm assuming that the file is small enough that you can read it all in one gulp. In that scenario, my first move is to define a FileStream object for the file I want to compress, read the file into memory, and close the FileStream:

More

Posted by Peter Vogel on 12/10/20150 comments


Creating a NuGet Web Site

In my regular Practical.NET column, I showed how easy it is to create NuGet packages and discussed how it was a much better way for a developer to share anything you've created, from Entity Framework classes to JavaScript files (my example was a package that implemented an HtmlHelper consisting of a DLL and a JavaScript file). NuGet also allows you to attach searchable documentation to your package to ensure that a developer can find your package, recognize it and know what your code does.

More

Posted by Peter Vogel on 12/03/20150 comments


Subscribe on YouTube