Attention: We have retired the ASP.NET Community Blogs. Learn more >

Contents tagged with Tips amp; Tricks

  • What version of Adobe Flash are you running?

    If you have ever done any customer support, you probably have a tool box full of different tools and utilities to help you get to the bottom of any customer issue that you run into.  I found another great tool the other day to help with investigation into Adobe Flash issues.

    This simple Adobe flash file will display the customers current Adobe Flash version:

    http://www.adobe.com/swf/software/flash/about/flashAbout_info_small.swf

    In Internet Explorer 8 I get this:

    image

    In Google Chrome I get:

    image

    Simple but yet so powerful.  So mighty customer support representative, make sure you have this tool on your utility belt.

    Technorati Tags: ,,
  • Visual Studio Shortcut: Surround With

    I learned a new Visual Studio keyboard shortcut today that is really awesome; the “Surround With” shortcut. 

    You can trigger the Surround With context menu by pressing the Ctrl-K, Ctrl-S key combination when on a line of code.

    Ctrl-K, Ctrl-S means to hold down the Control key and then press K and then while still holding down the Control key press S.

    Here is where this comes in handy:

    You type a line of code and then realize you need to put it within an if statement block. So you type “if” and hit tab twice to insert the if statement code snippet.  Then you highlight the previous line of code that you typed, and then either drag and drop it into the if-then block or cut and paste it.  That is not too bad but it is a lot of extra key clicks and mouse moves.

    Now try the same with the Surround With keyboard shortcut.  Just highlight that line of code that you just typed and press Ctrl-K, Ctrl-S and choose the if statement code snippet, hit tab, and POW!... you are done!  No more code moving/indenting required.

    Here is what the Surround With context menu looks like:

    image

    Just up or down arrow inside the drop down list to the code snippet that you want to surround your currently selected text with.  Did I mention this is AWESOME!

    Now it is so simple to surround lines of code with an if-then block or a try-catch-finally block... things that usually took several key clicks and maybe one or two mouse moves.

    And this works in both Visual Studio 2008 and Visual Studio 2010 which means it has been around for a long time and I never knew about it.

     

  • How to quickly comment or uncomment lines of code in Visual Studio

    When I am developing I am always trying to reduce the amount of time that my hands come off of the keyboard and have to move to the mouse.  One of the frequent functions that I noticed required me to move my hand off of the keyboard to the mouse is commenting or uncommenting lines of code.

    Visual Studio has two buttons in the toolbar to comment or uncomment a line of code (they are part of the Text Editor or HTML Source Editing Toolbars):

    image

    You can also achieve the same result by using the key combination Ctrl-K, Ctrl-C to comment out the currently selected lines or Ctrl-K, Ctrl-U to uncomment the currently selected lines. 

    Ctrl-K, Ctrl-C means to hold down the Control key and then press K and then while still holding down the Control key press C.  Ctrl-K, Ctrl-U means to hold down the Control key and then press K and then while still holding down the Control key press U.

    I have found this key combination to be difficult at first to remember (in the past I tended to always just instinctively go for my mouse) but now I have remembered to use that key combination regularly and have found it very helpful. 



  • Timestamp string with milliseconds from a System.DateTime

    You can easily convert a System.DateTime object into a string based on the current date and time by using the ToString() method of the DateTime object.  For instance:

    DateTime d = DateTime.Now;
    String s = d.ToString("yyyyMMdd-HHmmss");

    Will produce a string with the value of “20091018-232013” assuming the date/time was 10/18/2009 11:20:13PM at the time the code was executed.

    But did you know you can get the milliseconds of that System.DateTime object by using the “fff” format string:

    DateTime d = DateTime.Now;
    String s = d.ToString("yyyyMMdd-HHmmss.fff");

    Will produce a string with the value of “20091018-232013.456” assuming the date/time was 10/18/2009 11:20:13.456PM at the time the code was executed.

    I use this all the time when I need to append a timestamp to a log, a log filename, or just anything else that needs a quick way to turn a System.DateTime object into a string with milliseconds too.