Wednesday, December 10, 2008

Where can I download old versions of JetBrains' ReShaper?

Often times I've tried to find old version of JetBrain's amazing tool ReSharper (R#). Usually I have to settle with some download site. Which makes me feel a little uneasy. The other day I found the JetBrains' provided link. So I figured I would share with the world. http://www.jetbrains.net/devnet/docs/DOC-280;jsessionid=3B8C7B3BA56CA355357DE8E5437485E9

Monday, November 3, 2008

The "var" keyword works in .NET 2.0?

Just the other day I installed Resharper 4.1 into my copy of Visual Studio 2008. Once I loaded my .NET 2.0 web application Resharper started suggesting I replace my variable type declarations with "var"!

What's this? Isn't "var" a C# 3.0 (.NET 3.5 Framework) feature?

So for giggles I swapped int for var and did a solution build (Ctrl + Shift + B).

NO ERRORS!

I ran the web application.

NO ERRORS!

So I posed a question to my twitter friends.

Why is my C# project for 2.0 framework, compiling fine with "var"?

Turns out, it's all Visual Studio 2008 slight of hand. As Phil Japikse says:

@JustinKohnen it's syntactic sugar in VS2008. If you look at the IL, it compiles down to 2.0 compatible code.

Isn't that interesting? You can also use automatic properties, and object initializers too! After Phil opened my eyes, he wrote a great blog post about these Visual Studio 2008 Compiler Tricks.

A thanks to Phil Japikse, Leon, and Matt Brewer for the help.

Friday, August 22, 2008

FYI: I'm changing my feed URL

I just wanted to give my RSS people a heads up. Some time in the next few months I will be shutting down my old feed URL.

My new URL is:
http://feeds.feedburner.com/JustinKohnen

Please switch over when you get a chance. I'd hate to lose you as a reader.

Kindest Regards,
Justin Kohnen, Geek

Monday, August 11, 2008

When do browsers download images defined in Cascading Style Sheets?

Just the other day I was talking with a coworker about ASP.NET Themes. We were addressing a question about putting multiple Cascading Style Sheets (CSS) into a theme.

Unless you do something special, ASP.NET Themes adds a link reference to every CSS file in the theme directory. We were fine with this behavior even if the styles weren't used by the page, but what about all the background images defined in the style sheets?

Here's where we asked the question "When do browsers download images defined in Cascading Style Sheets?"

Here are my findings:

Both Internet Explorer 7 and FireFox 3.0 do not download an image unless the style is used on an element of the page.

For Example:

Consider a style sheet called style.css which containes

.image
{
 background:transparent url(testImage.png);
}

If you have a html file which contains:

<html>
    <head>
        <link type="text/css" rel="stylesheet" media="screen, projection" href="style.css">
    </head>
    <body>
        <p>Hello World</p>
    </body>
</html>

There will be two requests to the server: html, and css

If you have a html file which contains:

<html>
    <head>
        <link type="text/css" rel="stylesheet" media="screen, projection" href="style.css">
    </head>
    <body class="image">
        <p>Hello World</p>
    </body>
</html>

There will be three requests to the server: html, css, and png

I tested using FireFox 3.0 with FireBug (HEH HEH, FIRE!), and Internet Explorer 7 and Fiddler.

Friday, August 8, 2008

ASP.NET Development Tips/Tricks: Using "Attach to Process..."

I wanted to save this tip for later but I think it's too important to hold back. The one action of attaching to a process will save you minutes, that's right MINUTES, in your daily tasks.

You might have noticed in my last post about Keyboard Shortcuts I never mentioned the F5 key. That's because I never use it.

The F5 key is commonly used to "Start Debugging." Let's take a moment to walk thru what happens when you press F5. (Or click the green play button, or thru the menu Debug > Start Debugging)

2008-08-08_2244The F5 Way

  1. First, Visual Studio (VS) will build your startup project.
  2. Second, VS opens an instance of your configured browser and attaches to the browser's process.
  3. Third, VS will direct the browser to the start page of your start-up project.
  4. Forth, VS finally attaches to the process hosting ASP.NET
    1. w3wp.exe if you use IIS6
    2. aspnetwp.exe if you used IIS 5.5
    3. WebDev.WebServer.exe if you use the ASP.NET Development Server that comes with Visual Studio.

Now, lets assume you want to debug some new administrative feature you've added to your web application. After all of the "F5" steps, most likely you:

  1. Fifth, start on your start page (I'll assume Default.aspx)
  2. Sixth, click on the Login link
  3. Seventh, login with Username and Password
  4. Eighth, browse to the Administration page with the feature you want to test

Now, lets assume you have a bug in your code.  Your next step might be:

  1. Ninth, close the browser
  2. Tenth, change the code to fix the bug
  3. Goto First

The "Attach to Process..." Wayatp 

So, how can "Attach to process... " save you minutes? By not repeating the Second, Third, Fifth, Sixth, Seventh, Eighth, and Ninth steps from above.

Here is the process I use:

Once per day:

  1. Open Browser
  2. Browse to development website
    1. If Root: (http://localhost)
    2. If Virtual Directory: (http://localhost/vDirectory)
  3. Click Login link
  4. Login with Username and Password
  5. Browse to the Administration page where the new feature will be

That's right, I usually only do these 5 steps once a day.

Now, I write my new administrative feature. Then, it comes time to test my changes.

<note>
This is where my first three common "walks" of my last post become important.
</note>

  1. First, build the current web project if needed.
    1. (Alt, B, U)
  2. Second, attach to process hosting ASP.NET.
    1. w3wp.exe (Alt, D, P, W 3, Enter)
    2. aspnetwp.exe (Alt, D, P, A S P, Enter)
    3. WebDev.WebServer.exe (Alt, D, P, W E B, Enter)
  3. Third, switch to the open browser
    1. (Alt+Tab)
  4. Fourth, refresh page as appropriate
    1. (F5 or Ctrl+F5 or Alt+D, Enter)

Lets assume there is a bug in my new code. (I know it's hard to believe, but just for giggles lets assume.)

  1. Fifth, detach from the process hosting ASP.NET
    1. (Alt, D, D, [sometimes Enter])
  2. Sixth, change the code to fix the bug
  3. Goto First

Conclusion

By using "Attach to Process..." we save ourselves repeatedly launching and closing the browser, the login process, and the preliminary navigational steps to get to the code we want to test. These actions which took minutes and were repeated with every "F5" now are only done once.

Wednesday, August 6, 2008

For the lovers of techno and "The Orange Box: Portal"

I'm a developer that cannot code without music. Euro Dance Techno from di.fm is this ninja's weapon of choice. I don't think I could work for a company that didn't let me have my headphones.

Just the other day I can across a remix of "Still Alive" from the credits of "Portal" the video game. (Part of The Orange Box).

I wanted to give a shout out to Raddox for his mix, and let others know about some of his other awesome work. Namely, "I'll Follow You There," and the amazing "When I Was a Child."

Happy coding to all.

Monday, August 4, 2008

ASP.NET Development Tips/Tricks : Know your Keyboard

I've thought for a while about what tip I wanted to start with. I decided to begin with the keyboard because I'll mention what shortcuts I use in all future tricks.

I don't want to get into a debate of which is better "the keyboard" or "the mouse", (personally I use one to compliment the other) but there are a some things about your keyboard and Visual Studio (VS) that can shave a few seconds off your common daily tasks. I like to call these two tips "VS Keyboard Shortcuts" and "Walking the Menus."

VS Keyboard Shortcuts

Everyone should know Visual Studio IDE largely relies on the Command Pattern. Nearly every action in VS can be performed by a command, and most Add-ins rely on the command pattern too.

What does this give us? Two words: "Keyboard" "Shortcuts." You can essentially tie any command (save, build, copy) to a key combination.  These settings are controlled in the keyboard options dialog.

Tools > Options > Environment > Keyboard

2008-07-30_1911

In this dialog you can lookup all the commands, and assign key combinations to them.

If you see a command with a comma (',') in it, this means you pause.

For example "Ctrl+K, Ctrl+K" means hit "Ctrl+K" pause hit "Ctrl+K" again. Or, hold down the "Ctrl" key and hit the "K" key twice.

Some of the most common VS shortcuts I use are:

Ctrl+X Cut
Ctrl+C Copy
Ctrl+V Paste
Ctrl+Z Undo
Ctrl+Shift+Z Redo
Ctrl+S Save
Ctrl+G Go to line
Ctrl+Shift+B Build Entire Solution
Ctrl+K, Ctrl+K Add/Remove Bookmark
Ctrl+K, Ctrl+P Go to Previous Bookmark
Ctrl+K, Ctrl+N Go to Next Bookmark
Ctrl+M, Ctrl+O Collapse all (regions, methods, etc.)
Ctrl+M, Ctrl+P Expand All (regions, methods, etc.)
Ctrl+M, Ctrl+M Collapse/Expand Current
Ctrl+K, Ctrl+C Comment out Current Line or Selection
Ctrl+K, Ctrl+U Uncomment Current Line or Selection
F9 Add/Remove a breakpoint on the current line

Most of the common commands appear in the menus for quick reference.

2008-07-31_1830

Some general non-VS shortcuts I also use:

Alt+Tab Switch windows.
Ctrl+Right Arrow Jump one "word" to the right
Ctrl+Left Arrow Jump one "word" to the left
Ctrl+Shift+Right Arrow Un/Highlight one "word" to the right
Ctrl+Shift+Left Arrow Un/Highlight one "word" to the left

 

Walking the Menus

2008-08-04_1855Now, spend a few minutes exploring your menus and context menus. Look at all those commands and command categories. (Most having an underlined letter)

Using your Alt key and those underlined letters you can "walk the menus."

When you hit Alt, the menu bar gets focus. Use the letter shortcuts (the underlined letter) to select the action you want. This keeps you from taking your hands off your keyboard to grab the mouse to click the menus.

Some of my common "walks" are:

Alt, B, U Build Current Project (the project containing the document your working on)
Alt, D, P Attach the VS Debugger to a Process
Alt, D, D Detach the VS Debugger from all Processes
Alt, W, L Close all Documents/Tabs

The first three don't seem like much, but I'll explain how valuable they are in a later post.

Conclusion

The process of taking your hand off your keyboard home row, grabbing the mouse, dragging to target, clicking (repeated clicking if you have bad aim), and moving your hand back to the home row takes valuable seconds. Why not save them by learning a keyboard trick or two?

Wednesday, July 30, 2008

RadComboBox not working within a ModalPopupExtender

I just figured out a problem I was having with a Telerik RadComboBox within a ModalPopupExtender and I thought I would share. The Extender worked fine, but when I clicked on the ComboBox the sliding drop down would not show. Turns out all the controls were working just fine, it was a CSS problem. By default the ModalPopupExtender div is set to a z-index of 100001. The RadComboBox slide div is set to a z-index to 6000. Essentially, the slide div was under the popup div. You can fix the problem by boosting the z-index of the slide div. I did it with jQuery:
$(document).ready(function ()
{
 $("div.rcbSlide").css('z-index', 100002);    
});

Monday, July 28, 2008

"ASP.NET Development Tips/Tricks" are coming!

During my years of developing in Visual Studio and ASP.NET, I've learned a few things here and there which helped me become more efficient when creating applications.

At the risk of sounding stupid, I'm going to share with the community some tricks I've learned. I don't know how many posts there are going to be, but I hope something I say might have value to someone else.

Friday, July 18, 2008

Some tips and tricks to prevent Email Harvesting / Scraping

First a little background for those of you that don't know. The term Email Harvesting or Email Scraping comes from the trick some spammers use to get valid email addresses.

Overly simplified, harvesting works as such: Some automated program goes out to web pages and looks over the source HTML for text that matches email formats (name@domain.com or mailto:name@domain.com). This software then stores matches to a database for spamming later.

<rant>
Web developers pay attention, nothing erks me more then web sites that post my full email address for all to scrape. I don't think I'm the only one that feels this way.
</rant>

So how do you prevent your email from being harvested?
Here a couple of suggestions:

  • Be creative with how you present your email address so they don't match the standard format.
      • Examples include:
        • name at domain dot com
        • name shift+2 domain period com
        • String.Format("{0}@{1}.com", "name", "domain");
  • Use some type of masking javascript to obscure the email address

<script type="text/javascript">eval(unescape('d%6fc%75%6de%6e%74%2e%77%72%69%74e%28%27%3Ca%20%68%72ef%3D%22%26%23109%3Ba%26%23105%3B%6c%26%23116%3B%26%23111%3B%3A%26%23110%3B%26%2397%3B%26%23109%3B%26%23101%3B%26%2364%3B%26%23100%3B%26%23111%3B%26%23109%3B%26%2397%3B%26%23105%3B%26%23110%3B%26%2346%3B%26%2399%3B%26%23111%3B%26%23109%3B%22%3E%6ea%6de%3C%2fa%3E%27%29%3B'));</script>

<a href="&#109;a&#105;l&#116;&#111;:&#110;&#97;&#109;&#101;&#64;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;">name</a>

  • Use an anti-bot process
    • Example: (Google Groups)
      • Clicking on the ellipse (...) of the email takes you to a CAPTCHA form

groups
google-captcha

  • Use an email friendly URL shinker
    • Example: (tool used: http://is.gd)
      • Entered "mailto:name@domain.com" 
        and got http://is.gd/XBs 
        (try it - you should experience the standard behavior of a "mailto," usually launching an email client)

Of course this is all a cat and mouse game. The harder we make it to harvest our email address the smarter the automated software becomes to figure it out our obfuscation. We just got to stay a step ahead of that darn cat.

<disclaimer>
I offer my advice with not warrantee or guarantee. Feel free to run with anything, but use at your own risk.
</disclaimer>

Tuesday, June 10, 2008

Use Exception.ToString() instead of Exception.Message

All too often I see code that tries to log exceptions to some type of persistent storage for and later reference and error/bug tracking. Some might not be aware, but the second worst thing you can log is Exception.Message. (The first being "An error occurred.") What should you use instead? Exception.ToString()

There is a world of difference between the two. Here's an example:

   1: public partial class Default : System.Web.UI.Page
   2: {
   3:     protected void Page_Load(object sender, EventArgs e)
   4:     {
   5:         try
   6:         {
   7:             int zero = 0;
   8:             int divisionbyZero = 42 / zero;
   9:         }
  10:         catch (Exception caughtException)
  11:         {
  12:             System.Console.WriteLine(caughtException.Message);
  13:             System.Console.WriteLine(caughtException.ToString());
  14:         }
  15:     }
  16: }

When I debug, here is what I get from line 12:

Attempted to divide by zero.

And from line 13:

System.DivideByZeroException: Attempted to divide by zero.
   at Demo.Web.Default.Page_Load(Object sender, EventArgs e) in C:\Working Copies\Demo\Demo.Web\Default.aspx.cs:line 23

Which would you rather see in a system error log?

My recommendation when writing to an error log "Use Exception.ToString() instead of Exception.Message."

Saturday, April 5, 2008

Recap: Brian H Prince on "Soft Skillz" for developers

Recently at the Dayton .NET Developers Group Brian H. Prince gave a presentation titled ""

Got to say, I thought the presentation was great. Had good humor, and Brian's passion for the subject matter really shines thru.

What did I get out of it?

One of the biggest things to stick is not all mentors have to be technical mentors. You can learn a lot from managers, sales reps, even from your clients.

He also mentioned you need to keep reading. Read at least one book a month, and mix it up a bit. Read about other subjects, not just technical. Exploring these other areas will help you think of new ways to write your code.

I could keep going but I don't want to spoil too much for developer's attending the CODODN.

If you're coming to the Central Ohio Day of .NET (CODODN) make sure to set some time aside for Brian's "Soft Skillz" presentation.

Tuesday, April 1, 2008

.NET 3.5 LINQ and Inner, Outer Joins

During my Visual Studio 2008 Install Party presentation at the Dayton .NET Developers Group. Someone asked the question

"Can you do joins with LINQ?"

I thought I would share a great blog post from K. Scott Allen titled: Inner, Outer, Let's All Join Together With LINQ.

Sunday, February 24, 2008

Using Windows Live Writer for Blogging

Some of you may have noticed my blog posts have actually increased as of late. Why? I used to use Blogger's online editor and the trouble I had with it really pushed me away from writing posts. I want my posts to look just the way I want, and the editor kept taking liberties with my visual formatting. SO FRUSTRATING!

So I posted the query to Twitter:
"I'm taking a poll: What is your favorite blog editor?"

Since then I've started using, you guessed it, Windows Live Writer.

So far I'm loving it, every post I've made matches the preview. Just like a WYSIWYG should. I've also started playing with the "Plug-ins."

I've recently added Insert Code Plug-in. Awesome! No more images of code for me. Here's a sample of what it does:

Inserting HTML Code (but I'm using XML):

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <services>

Inserting C#:

public static void SomeMethod(string someString)
{
Console.WriteLine(someString);
}

Inserting TSQL:

CREATE PROCEDURE someStoredProcedure
@someMsg varchar(256) = NULL
AS
BEGIN

I can only imagine what other tools will be coming out in the future. So for right now Windows Live Writer is for me.

Tuesday, February 19, 2008

Cincinnati Users Group and the Version Control Panel

Well I just finished up being part of the Source Control Panel at the Cincinnati Users Group.

I was very enjoyable. I think I did a fine job representing Subversion. Those of you that read my blog know that I got a good understanding of the system and methodology.

For those that are interested, I tend to tag allot of my research

Actually, I was quite surprised there weren't more questions about "Version Control Best Practices," "Branching Options," and "Database Versioning"

At the end there was much discussion about the "additional features" of TFS. I thought that was a bit unfair to SVN. SVN was designed to be nothing more then Version Control. Do one thing, and one thing well, right?

<PersonalOpinion>

Sure SVN doesn't have the "baked in" features like TFS does (and I'll admit TFS' integration is awesome) but with a few extra steps you can have work item tracking with trac. If you want Continual Integration you can always run CI Factory. If you want a better repo viewing experience you can install Fisheye. If you want code review you can run Crucible. With Subversion you have so many options.

Actually, I think being able to "choose" which tools you want to mix and match is a huge perk of using SVN. However, you do have to write the "glue" that holds it all together.

</PersonalOpinion>

All in all I had a really great time. There were a flurry of good questions and conversation. In the end, I just hope I helped someone learn something.

Remember,

Any version control is better then no version control.

P.S. If you have any additional questions about version control, ask away. I would be happy to address them.

Regular Expression Negation for Required Field Validators

Out of the box ASP.NET regular expression validators have the following behavior:

Does control value match regular expression? If yes validation passes, else validation fails.

But what if you wanted the following:

Does control value NOT match regular expression? If yes validation passes, else validation fails.

Turns out there is no "If expression not match" property on a regular expression validator. Now, you can make your own custom regular expression control, or you can buy a toolset. But it turns out you might be able to do it in your regular expression itself.

This can be accomplished by using something called a Negative lookahead assertion. It succeeds if the contained expression doesn't match at the current position in the string.

The syntax is

(?!&lt;value>)

For example, say you wanted to prevent users from using an email address that contained "@spam.com". You could use the following RegEx:

*@(?![Ss][Pp][Aa][Mm][.][Cc][Oo][Mm]$).*

Now your regular expression validator will pass if their value does NOT match the regular expression.

Regular Expression are extremely powerful, and I encourage everyone to learn about them. If you can master them, consider yourself a superhero.

Sunday, February 17, 2008

Visual Studio 2008 Tour and Install Party

This month (February 27, 2008 18:00) I'll be speaking at the Dayton .NET Developers Group about Visual Studio 2008 and .NET 3.5.

The official blub is:

Visual Studio 2008 and .NET 3.5 are soon to be released, after a very public and open beta process. We will run around the products, and discuss what the new features are. This will briefly cover VS, WCF, WF, C# and VB.NET features.

<RandomSideNote>
I'm actually filling in for Brian Prince, who was filling in for Jeff Blankenburg. Both of whom are very busy men. Being that I'm a single guy, with no kids, or pets I figured I could jump in and help out. People seemed to be excited about this upcoming meeting, I just couldn't let it be canceled.
</RandomSideNote>

Saturday, February 16, 2008

I'll be on the Source Control Panel on February 19, 2008 18:00

The Cincinnati User's Group (Cinnug) has asked me to be a part of the "Source Control Panel" they are having on Tuesday February 19, 2008 at 1800.

This meeting is different then those I've been in before. It's an open panel for group members to come and ask questions about VSS, TFS, Harvest, ClearCase, Vault and Subversion.

I'll be there primarily as a Subversion resource, but I'll try to fill in on VSS and TFS where I can.

Short notice I know, but if you're not doing anything Tuesday, come on down an heckle me. I think it's going to be a lot of fun.

Central Ohio Day of .NET - April 19, 2008

CentralOhioDoDNLogo_smallIt's that time again. Time for us developers to get together and geek out to the latest technology and see who's smarter. ;)

Day of .NET events are a series of mini-conferences organized by developers for developers. The event it FREE to to all.

Visit the event's homepage, and register today.

For those that have attended the Dayton Cincinnati Code Camps  of the past, this year we've included the Columbus .NET user group as well. Because "The Central Ohio Dayton Cincinnati Code Camp" was just to much to say, and CODCCC had just too many C's. The name has been changed to "Central Ohio Day of .NET", or CODODN. Ah, just better.

But seriously, becoming part of the Day of .NET events makes it easier for coders to find us, and helps coders find similar events going on in their areas.

CentralOhioDoDNBadge Though the name may be different, it's the same great event. So come, meet new people, share ideas, socialize, and maybe learn something too.

Wednesday, February 13, 2008

Getting a list of .NET exceptions with Resharper.

Often I'm programming C#.NET and want to throw an exception but I don't know what exception to throw. I think "wouldn't it be nice if there was an easy way to get a list of the exceptions in .NET?"

I've Googled, I've dug thru the MDSN, then it hit me...

DUH! Resharper's intellisense.

A simple "throw new" gives you:

2008-02-14_1858

 

And you can use the "Navigate from here to Base" feature to get a more detailed list.

Just type "System.Exception" and hit the Resharper 2.x shortcut: Ctrl + Alt + B

Navigate_To_Base

Tuesday, February 5, 2008

Parsing a URI / URL in C# and VB.NET

I used to spend time parsing a URL string using old fashion .NET string methods. (Contains, Split, Substring, IndexOf, etc). I always thought, "There must be a better way to do this."

And there is, there is a tool in the .NET Framework to help you parse a fully qualified URI path.

System.UriBuilder

A few simple lines of code

2008-02-06_0508

Does a lot of the work for us.

2008-02-06_0507 

And this is just one of the Uri tools. I encourage you to look at the others as well.

  • System.Uri
  • System.UriComponents
  • System.UriFormat
  • System.UriHostNameType
  • System.UriIdnScope
  • System.UriKind
  • System.UriParser
  • System.UriPartial
  • System.UriTypeConverter