Archive for 'Code'

Adding the NHibernate Schema Files to Visual Studio 2010

Since I can never remember the steps on how to do do this, if you need to add the Schema Definition files (.xsd) from NHibernate to Visual Studio 2010, here are the steps you need to follow: Download the latest version of NHibernate Copy nhibernate-configuration.xsd and nhibernate-mappng.xsd to C:\Program Files\Microsoft Visual Studio 10.0\Xml\Schemas\ Restart Visual [...]

TFS Merging Infinite Loop Madness

I made a bug fix to the trunk of one of my projects, which included a change to the project file. When I tried to merge the trunk into my development branch in TFS, I double clicked on the solution file before I commited my changes. Now, Visual Studio is reporting this error message in [...]

Fixing Broken Paging Links in WordPress Running on Windows

Note:Updated instructions for WordPress 3.0 can be found here. I periodically review Google Analytics and Google Webmaster Tools for a couple of different sites I that manage, and I noticed that there were several pages on my blog with broken links. It turns out that on any page with a link to “Recent Posts” or [...]

Merging a .NET .DLL into an .EXE with ILMerge

I am currently working a C# console application that I want to be able to easily deploy onto multiple machines. Currently, it is referencing about a half a dozen other DLL’s that I don’t want to have to deploy along with it. I really, really wanted to be able to deploy a single file via [...]

Production Surprise

I found this while I was debugging a minor production problem this afternoon. if (userName.Contains("")) userName = GetUserName(userName);   if (String.IsNullOrEmpty(userName)) throw new ArgumentNullException("userName can not be null. Verify identity.Name is not empty."); This code was written last month during a refactor of this method, and I can not for the life of me understand [...]

Creating a Database Object in DAAB from a Dynamic ConnectionString

When using the Database Access Application Block in the Microsoft Enterprise Library, you can define a Database object from a ConnectionString in your project app or web.config. In my latest project, I needed to create a ConnectionString from information the user enters in the login form. After a little trial and error, this is what [...]

Preventing the User from Navigating Away from a Dirty Page

A bug popped up in testing today in some code a wrote a few months ago to prevent our users from navigating away from a modified page. When I did my initial testing, I neglected to test the case where the user makes a change to a single control and then clicks the back button [...]

Sorting a Generic List By Object Properties

I found this the other day.  When you need to quickly sort a generic list by some property, this is MUCH simpler then using Comparers. List<Person> people = repository.GetAll(); people = people.OrderBy(x => x.LastName).ToList(); or List<Person> people = repository.GetAll(); people = people.OrderBy(x => x.LastName).ThenBy(x => x.FirstName).ToList();

Preventing a LinkButton from Posting Twice During a Double Click

Apperently, you can’t count on the users not double-clicking on a link. I found this during a Google search and it seems to be working fine. protected void Page_Load(object sender, EventArgs e) { this.LinkButton1.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(this.LinkButton1, "")); } This disabled the link on the first click, then postbacks the form via the __doPostBack Javascript [...]

When Environment.CurrentDirectory Isn’t

I have been using Environment.CurrentDirectory for years as a way to programatically access the folder the application is running out of.  In most cases, I was just displaying this information somewhere, or maybe defaulting a Save or Open File Dialog box. I my current project however, I wanted to Process.Start a batch file residing in [...]