Search This Blog

Thursday, May 20, 2010

Terminal server client / delete key irritation

I've noticed when using a terminal server client session that sometimes the "Delete" key stops working correctly -- pressing it sends a "CTRL-ALT-DEL" to the server, bringing up the "Lock Workstation / Logout / Change Password" dialog box.

You forget how much you use that key when coding until you can't use it, and having it not work and being forced to use the backspace key can be a real drag.

The solution: Press "CTRL-ALT-END". The DEL key will start working again.

Saturday, March 27, 2010

Regex Match/Group syntax in .NET

I'm used to doing this in UNIX and there it's a lot easier. But I live in a .NET world.

For handling matching with REGEX you need to use the "Groups" construct of the "Match" object in .NET. An example says it all -- say I'm looking at a string followed (optionally) by an integer:

private Regex regex1 = new Regex (
"([a-zA-Z]+)([0-9]*)",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);


This was used for creating a unique name in an Active Directory database -- a name was suggested and, if there's a collision, it takes the name and tacks a number to the end (e.g., "SSMITH" collides; suggest "SSMITH1"). It then checks that one against the Active Directory and if it sense a collision again it breaks it apart and increments the trailing number ... lather, rinse, repeat until a unique name is found. Here's a chunk that indicates the use of REGEX groups in .NET:

// Break current name down into text and integer increment components
Match mc1 = regex1.Match(ProposedSAMAccountName);
ProposedSAMAccountNameText = mc1.Groups[0].Value.ToString();
if (mc1.Groups[2].Length > 0) ProposedSAMAccountIncrement =
Convert.ToInt32(mc1.Groups[2].Value)++;


The first member of the "Groups" collection is the entire matching expression, the second is the first matching group, the third is the second matching group, etc.

This'll be the third time I've wasted an hour re-figuring out something so intuitive in PERL and UNIX. This syntax in .NET just seems awkward, I don't think I'll ever speak it without an accent.

I'll just add this to this cheatsheet because I'm sure this'll come up again.

Monday, March 8, 2010

Simple build versioning in VS2008

Visual Studio 2008 provides a simple build versioning system already built in.

You only need to edit the "AssemblyInfo.cs" file (in the "properties" section of a project) of a project/assembly and reset the entry:

[assembly: AssemblyVersion("1.0.0.0")]

to

[assembly: AssemblyVersion("1.0.*")]

It even describes how to do it in the comment section of the file.

Then you can reference the build version with calls to the assembly object thru reflection like this:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()

It'll automatically update the build number after each new build. The updated numbers represent some sort of increment from some date in the past (1/1/2000? See the MSDN article for more details). For our purposes we just needed an incrementing number to show the latest version, so this works fine as a quick fix.

Sunday, February 28, 2010

Path to current website directory in ASP.NET

I'm working on a standard name/address web app for permitting users to update their personal information.

The client wants to provide forced-choice options for certain fields in the active directory user object. He gave me some Excel files that I changed to XML files which the dropdown controls on the web form access. For example, he wants people to choose their "Department" field from a fixed list. Simple enough.

To improve the look/feel of the app I needed to have the webpage code to actually read that XML file to do a lookahead and pre-load a dropdown list position, but it was difficult to tell the codebehind code where exactly to look.

The solution was to preface the name of the XML file that I needed to read with the value "Request.PhysicalApplicationPath" -- that points it directly into the directory on the web server.

Monday, February 22, 2010

"An Exchange 2007 Server on which an address list service is active cannot be found" error

Another note to myself ...

This error means that the "Microsoft Exchange System Attendant" service on the Exchange 2007 server has stopped. Restart it and that should solve that particular problem.

Setup project always fails on build in VS2008

When setting up a setup project for a .NET 2.0 windows service in Visual Studio 2008 I ran into a novel problem this morning -- the setup project itself would always fail to build but wouldn't leave any error messages behind.

A Google search turned up a recent complaint about this in StackOverflow (http://stackoverflow.com/questions/847893/visual-studio-setup-and-deployment-build-fails-with-no-errors) but it wasn't exactly on target.

It provided enough clues to give me a workaround -- it seems to be related to the LINQ to SQL add-ins when making the setup project. The temporary answer was to create a new setup project, explicitly making it a .NET 2.0 project, and then try the build.

This made it work fine.

It'd be interesting to try and find a good solution for the problem but this works for now.

Monday, February 15, 2010

Getting JQuery Intellisense working in Visual Studio 2008

People have been using JQuery in Visual Studio successfully for over a year and there are a lot of links on how to set it up, but I thought I'd write myself a few notes on how to do it since I'm finding myself doing it on various machines (work desktop, home desktop, netbook, etc.) over time and need a quick cheat sheet.

1) Get the latest version of jquery from JQuery at http://docs.jquery.com/Downloading_jQuery. As of this writing it's version 1.4.1. Download the "jquery-1.4.1.js" file (the uncompressed version) and the related Visual Studio documentation file, "jquery-1.4.1-vsdoc.js."

2) Make sure you've got SP1 installed on Visual Studio 2008. You can check to see if it's installed by going to the "Help" tab and then the properties menu to check if the service pack has been installed:



















If it isn't installed, you can get it here: http://www.microsoft.com/downloads/details.aspx?FamilyID=27673c47-b3b5-4c67-bd99-84e525b5ce61&displaylang=en

Note on installing the service pack: Be prepared to give it like 40+ minutes to run, plus have your Visual Studio 2008 release DVD around (or have the install files available somewhere on the hard disk) since it'll be asking for it during the upgrade.

3) Download the hotfix from Microsoft to support Jquery Intellisense:
http://code.msdn.microsoft.com/KB958502/Release/ProjectReleases.aspx?ReleaseId=1736

4) Test it out with a small JQuery project. Create an ASP.NET web project, then add a "scripts" folder to the project and copy both the JQuery files downloaded earlier ("jquery-1.4.1.js" and "jquery-1.4.1-vsdoc.js") into it; add a "script" section to the ASP.NET markup of the page and add a reference to the JQuery file (see illustration) and type "$" to see if Intellisense is up and working -- :
















5) Typing a period after the dollar sign ("$.") should produce more JQuery Intellisense documentation and indicates that Intellisense and JQuery are now working together fine: