Thursday, June 21, 2012

Determine which process has a file locked - Windows 7

Are you getting that "can't delete" or "can't rename" a file because it is in use message.  On Windows 7 you can use the Resource Monitor (just type the name into the Start search box to find it) to easily find out which process has a file locked.

Start the Resource Monitor and switch to the CPU tab.  Just type the file name into the Associated Handles search box and you will be able to see which processes have matching file names locked.  To kill the process, just right-click and choose "End Process".

Easy as pie and all part of Windows 7.


Tuesday, June 12, 2012

Better regular expression for phone numbers (multiple formats)

I'm often surprised at how often websites only accept a specific format for phone number input (U.S.) so I thought I would post a more flexible input format.

We want to allow users to enter phone numbers in formats like:

(123) 456-7890
123-456-7890
123.456.7890
1234567890

Using a regular expression, we can allow all these formats and more.


^\s*[(]?(?<AreaCode>\d{3})[)]?(\s*|[.-])(?<Prefix>\d{3})(\s*|[.-])?(?<LineNumber>\d{4})\s*$

Notice that we specify regular expression group names to easily pick up the phone number parts. In C#, this can be done like:

Code:
string prefix = match.Groups["Prefix"].Value;

Finally, here the some C# code to kick things off.

Code:
Regex rePhone = new Regex(@"^\s*[(]?(?<AreaCode>\d{3})[)]?(\s*|[.-])(?<Prefix>\d{3})(\s*|[.-])?(?<LineNumber>\d{4})\s*$");
Match match = rePhone.Match("123.456.7890");
Console.WriteLine(match.Success);

Monday, June 11, 2012

Monday, May 21, 2012

Ever want to see SQL JOIN statements visually? Let's assume we have two tables, Person and Pet.

Click on the image below for a full view.

Tuesday, April 10, 2012

Monday, April 2, 2012

Nice cheat sheet on many HTML5 and CSS3 features

Here is a nice cheat sheet for some of the more requested items related to HTML5 and CSS3.  Not too bad.

Stories In Flight

Sunday, April 1, 2012

ASP.NET generic content box with title and body

Here is a quick example of creating a simple ASP.NET web control that allow you to have a region/box that contains a title and body where each of three elements can each have their own CSS class.

You can use the content box in a web page like:

Code:
using System.Web.UI.WebControls;

namespace CarverPainting
{
   public class ContentBox : Panel
   {
      public string CssClassBody
      {
         get { return base.CssClass; }
         set { base.CssClass = value; }
      }

      public override string CssClass
      {
         get
         {
            return ViewState["CssClassMain"] == null ? string.Empty : ViewState["CssClassMain"].ToString();
         }

         set
         {
            ViewState["CssClassMain"] = value;
         }
      }

      public string CssClassTitle
      {
         get
         {
            return ViewState["CssClassTitle"] == null ? string.Empty : ViewState["CssClassTitle"].ToString();
         }

         set
         {
            ViewState["CssClassTitle"] = value;
         }
      }

      public string Title
      {
         get
         {
            return ViewState["Title"] == null ? string.Empty : ViewState["Title"].ToString();
         }

         set
         {
            ViewState["Title"] = value;
         }
      }

      protected override void Render(System.Web.UIHtmlTextWriter writer)
      {
         bool hasClass = !string.IsNullOrWhiteSpace(CssClass);
         bool hasClassTitle = !string.IsNullOrWhiteSpace(CssClassTitle);
         bool hasClassBody = !string.IsNullOrWhiteSpace(CssClassBody);

         // contentbox class
         writer.Write("<div{0}>", hasClass ? string.Format(" class=\"{0}\"", CssClass) : string.Empty);

         if (!string.IsNullOrWhiteSpace(Title))
         {
            writer.Write("<div{0}>{1}</div>", hasClassTitle ? string.Format(" class=\"{0}\"", CssClassTitle) : string.Empty, Title);
         }

         base.Render(writer);

         // contentbox class
         writer.Write("</div>");
      }
   }
}

Using dotlesscss with Visual Studio and IIS

I've started to use LESS the dynamic stylesheet language with Microsoft's ASP.NET.  For starters, it really does help write and maintain stylesheets.  The .NET version can be downloaded at http://www.dotlesscss.org/.

I did however run into an issue when I deployed my development code to a production server.  It turns out that the Visual Studio 2010 web server handles the dotlesscss DLL differently from IIS 7.5.  In a nutshell, to use dotlesscss in both environments (local, production) without having to made changes to one of the environments the setup I use is:
  1. Set my web project to use IIS Express (separate download from Microsoft).
  2. Add the following items to my web.config file
xml version="1.0" encoding="utf-8"?>

<configuration>
   <configSections>
      <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
   configSections>
   <system.web>
      <compilation debug="true" targetFramework="4.0" />
      <pages>
         <controls>
            <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
         controls>
      pages>
   system.web>
   <system.webServer>
      <handlers>
         <add name="dotless" type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.less.css" verb="*"/>
      handlers>
   system.webServer>
   <dotless minifyCss="false" cache="false" />
configuration>


Wednesday, February 29, 2012

Why does copy/paste not work with Remote Desktop

So what do I do when clipboard stops working when you are using Windows Remote Desktop?

Fixing the issue is pretty straightforward and involves a few basic steps.
  1. Load up task manager (right click taskbar and select Task Manager)
  2. Go to the Processes Tab
  3. Select rdpclip.exe
  4. Click End Process
  5. Go to the Application Tab
  6. Click New Task
  7. Type rdpclip
  8. Click OK

That should get things going again.

Sunday, May 15, 2011

MVC 3, Razor, and Entity Framework Code-First

Here is a good tutorial (and downloadable PDF) on using MVC 3, Razor, and the EF Code-First (Code-First CPT 5 Release).

Visit Tutorial

I think the best part about the tutorial is how Code-First makes it really simple to set up pure POCO objects for data access.

Friday, January 21, 2011

Visual Studio 2010 Find/Replace Dialog Growing

For anyone interested in fixing their ever growing find dialog in Visual Studio 2010, there’s now a patch from Microsoft:

Download Growing Find and Replace Dialog

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...