ASP.NET Diagnostic Page to Dump ASP.NET and Environment Configuration

<%@ Page Language="C#" AutoEventWireup="true" Trace="true" TraceMode="SortByCategory" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>ASP.NET Diagnostic Page</title>
</head>
<body>
  <form id="form1" runat="server">
  
  <h2>Environment Variables</h2>
  <pre>
  <table>  
<%
    var variables = Environment.GetEnvironmentVariables();
    foreach (DictionaryEntry entry in variables)
    {
      Response.Write("<tr><td>");
      Response.Write(entry.Key);
      Response.Write("</td><td>");
      Response.Write(entry.Value);
      Response.Write("</td></tr>");
    }
  %>
  </table>
  </pre>

  <h2>Misc</h2>
  <pre>
  Response.Filter = <%= Request.Filter.ToString() %>
  Request.ApplicationPath = <%= Request.ApplicationPath %>
  Request.PhysicalApplicationPath = <%= Request.PhysicalApplicationPath %>
  Request.PhysicalPath = <%= Request.PhysicalPath %>
  Request.UrlReferrer = <%= Request.UrlReferrer %>
  Request.UserLanguages = <%= string.Join(",", (Request.UserLanguages ?? new string[0])) %>
  </pre>
  
  </form>
</body>
</html>

Source: http://www.codeproject.com/Articles/229356/ASP-NET-Diagnostic-page-to-dump-ASP-NET-and-Enviro

How to Re-Enable Create Unit Tests Context Menu In Visual Studio 2012

To re-enable the Create Unit Tests… menu, go to Tools->Customize… to launch the Customize dialog. At the Customize dialog, go to the Commands tab, select the Context menu radio button and choose Editor Context Menus | Code Window.

You will realized that the menu item is actually available in the context menu. 🙂 The VS developers were kind enough to leave it there for us. *HeHe* Click on the Create Unit Tests… menu item and click either Move Up or Move Down. [Note: My screenshot is showing Create Unit Test in singular because I had previously tried to rename it]. Then click Close.

Restart Visual Studio 2012 and whalla! The context menu will be available!

 
Note: This apparently does not work in Visual Studio 2013.
 
Alternative is to use this Visual Studio Extension: Unit Test Generator
 

Get CSS/JS Intellisense In ASP.NET WebForms Using Visual Studio 2013

In Visual Studio 2013, CSS files that are included in your project/solution will now automatically be parsed and all HTML documents will gain CSS class intellisense.

But:

ASPX and other WebForm files using the legacy editor do not benefit from this implementation in VS 2013, but may adopt the new system in future releases.

But you can still use this feature as follows:

  1. right click on the “default.aspx” file in the Solution Explorer
  2. “open with”
  3. select “HTML Editor”
  4. “ok”

Source

 

Navigate To Feature In Visual Studio 2012/2013

Visual Studio’s Navigate to feature allows you to find and navigate to a specific element in your solution. Once you press the Ctrl+, combination and start typing your query*, Visual Studio will display all found elements matching your query, regardless of their type and location. To navigate to a certain element, either select it with cursor keys and press Enter or double click the element.

gte_vs[1]

Best Way To Clone An Object In .NET

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

/// <summary>
/// Reference Article http://www.codeproject.com/KB/tips/SerializedObjectCloner.aspx
/// Provides a method for performing a deep copy of an object.
/// Binary Serialization is used to perform the copy.
/// </summary>
public static class ObjectCopier
{
    /// <summary>
    /// Perform a deep Copy of the object.
    /// </summary>
    /// <typeparam name="T">The type of object being copied.</typeparam>
    /// <param name="source">The object instance to copy.</param>
    /// <returns>The copied object.</returns>
    public static T Clone<T>(T source)
    {
        if (!typeof(T).IsSerializable)
        {
            throw new ArgumentException("The type must be serializable.", "source");
        }

        // Don't serialize a null object, simply return the default for that object
        if (Object.ReferenceEquals(source, null))
        {
            return default(T);
        }

        IFormatter formatter = new BinaryFormatter();
        Stream stream = new MemoryStream();
        using (stream)
        {
            formatter.Serialize(stream, source);
            stream.Seek(0, SeekOrigin.Begin);
            return (T)formatter.Deserialize(stream);
        }
    }
}

In case you prefer to use the new extension methods of C# 3.0, change the method to have the following signature

public static T Clone<T>(this T source)
{
   //...
}

References:
http://stackoverflow.com/questions/78536/deep-cloning-objects/78612#78612
http://www.codeproject.com/Articles/23832/Implementing-Deep-Cloning-via-Serializing-objects

How To Retain Leading Zeros (0) In CSV Files

When adding a value with a leading zero. for example 05710. Add additional quotes and equals:
"=""05710"""

With the CSV file resembling this:

a,b,c,d,e,f,"=""05710""",h,i

Sources:
http://social.msdn.microsoft.com/Forums/en-US/aae07b39-865f-4c68-a07f-7cad2dfd6733/how-do-i-open-csv-using-excel-without-deleting-leading-zeros?forum=isvvba
http://nebula-rnd.com/blog/tech/2009/07/excel-csv1.html