Prevent cutting or copying blank lines in Visual Studio

(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. I hope you know that we are not required to select a line to cut or copy it in Visual Studio, you can just keep the caret in a line and press Ctrl + C or Ctrl + X and the text in the line will be copied to your clipboard and you can insert this line anywhere in your code by pressing Ctrl + V. It will also copy a blank line, but people use Ctrl + X command to delete blank lines and some may find this as an issue as they didn’t intend to copy the blank line and also it will clear the previously copied item in the clipboard. It is surprising as usual to find that Visual Studio team has thought out this and provided a setting which prevents the copying of blank lines, and Cut command will just delete the blank lines. I found this when I recently bumped into the setting in Visual Studio, in Text Editor > All Languages called “Apply Cut or Copy commands to blank lines when there is no selection“.

Have you tried AutoHotkey tool

(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. AutoHotkey is a great FREE and open-source tool you can use to create hotkeys and assign them to commands that you can execute on your system. You are asked to create a script file with commands and then open it in the AutoHotkey program to use it. Commands are executed based on the hotkeys assigned to them in the script. In the script, you can specify simple commands like the one shown below. #n::Run Notepad The above command launches Notepad. # stands for Windows key, ^ for Control key, ! for Alt and + for shift You can find more commands and general usage info about AutoHotkey in the tutorial page here.

A new feature in ASP.NET 4: Shorthand syntax for Html Encoding

(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. So far if we need to HTML encode content that we throw out to the response stream we will use Server.HtmlEncode() method as below.   <%= Server.HtmlEncode(“Content”) %>   Now in ASP.NET 4 we have a new code syntax, which comes handy whenever you want to emit content with HTML encoding, the new syntax is <%: … %> the “=” character is replaced in this new syntax by the “:” character, as shown below. <%: “Content” %>

Do you know Notepad’s .LOG feature?

(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. Thought of posting a simple feature of notepad that might be useful for many who log things in a file for various purposes, mostly this can be used for simple things that needs to be logged. In Notepad, type “.LOG” (case sensitive) in first line of the file and save it, now close and reopen the file, current date and time will be inserted in the last line and you can type information and save.

A tip when working with QueryStrings

(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. We still use QueryStrings for many reasons even though we have other methods to deal with HTTP requests to web applications. And when working with QueryStrings, I hate to type Request.QueryString(“blah”), Request.QueryString(“blahblah”), Request.QueryString(“blahblahblah”), etc., again and again when I need to. This is more tiring if there are more number of QueryString items to deal with. If you note, Request.QueryString is actually a NameValueCollection. So in suitable situations I would love to use a NameValueCollection object with a short name instead of Request.QueryString(“blah”) 😉 as shown below. This saves time and provides a little better coding experience. NameValueCollection q = Request.QueryString; Response.Write(“name” + q[“name”]); Response.Write(“address1” + q[“address1”]); Response.Write(“address2” + q[“address2”]); Response.Write(“city” + q[“city”]); Response.Write(“country” + q[“country”]);

The (not much utilized) Debug->Exceptions… window technique

(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. The Debug-Exceptions… window is a useful tool that at times saves lot of time when debugging. Even though this exists (i think)from Visual Studio 2003, I Still find people struggle a bit with the situation I am going to explain next.[more] As you know Visual Studio highlights the exception code line when it is not handled. Sometimes we purposely don’t handle exceptions in a method and let the exception thrown to calling functions.   Usually we have a multi-project solution that typically has layers like Business logic, Data access layer, UI, etc. Imagine that you make a call from the UI to a local function and it calls another function in BLL and the call goes deep into layers of your project architecture. Now, when it is not sure if each of the methods getting called handles exceptions in it or doesn’t throw identifiable exceptions. For instance.. private void Function_A() {     try     {         BLLFunction();//this calls few other functions..     }     catch (Exception ex)     {         //handle exception     } } Function_A() calls BLLFunction() and it again calls few other functions,