Category name:Development

Get the physical path of a path that uses a subst drive

My previous employer used a tool to attach databases that were located on a substituted path. I needed this conversion logic in another kind of environment and used the almighty google. So I hit an article on Avner Kashtan‘s blog titled Query SUBST information . His code sample proved very usefull but it didn’t support relative paths on the current drive so I altered it a bit. Below is my version and put it here for other people to use and abuse.

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

public static class Subst
public static string GetRealPath(string path)
const string MSG_PATH_INVALID = "The path/file specified does not exist.";
const int BUFFER_LENGTH = 1024;

if (path == null) throw new ArgumentNullException("path");
if (Directory.Exists(path))
path = new DirectoryInfo(path).FullName;
else if (File.Exists(path))
path = new FileInfo(path).FullName;
throw new ArgumentException(MSG_PATH_INVALID, "path");

string realPath = path;
StringBuilder pathInformation = new StringBuilder(BUFFER_LENGTH);
string driveLetter = Path.GetPathRoot(realPath).Replace(@"", string.Empty);
QueryDosDevice(driveLetter, pathInformation, BUFFER_LENGTH);

// If drive is substed, the result will be in the format of "??C:RealPath".
// after that strip the ?? prefix and combine the paths.
if (pathInformation.ToString().Contains(@"??"))
string realRoot = pathInformation.ToString(4, pathInformation.Length-4);
realPath = realRoot + realPath.Substring(2); // Remove the drive letter

return realPath;

static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);

I tried to use Manoli’s csharp to HTML formatter but it screws up. So no syntax coloring this time.

VS2005: Solution to ‘Where is that damn exception dialog?’

Today I had a very annoying issue. I was debugging an application on an VS2005 instance of a computer that I did not prepare / installed myself. I wanted the “break on all exceptions” behaviour in the debugger. Normally you just go to the menu and select Debug -> Exceptions. But I was quite surprised that the Exception dialog menu item wasn’t available. Luckely the shortcut key CTRL+E still worked and I was able to continue debugging.

But I still wanted to know why the option was not available so after brainstorming I thought that it should be the IDE customization. I wanted to see if it was caused by the ‘default’ view in this instance and went to Tools -> Import and export settings. It was indeed the view because it stated Business intelligence settings. It was probably caused by the SQL2005 installation.

But that’s not all! The behaviour of the VS2005 Exception dialog differs with VS2003. In VS2003 you can make a selection of exceptions on which the debugger should break. But sometimes you want to just do a few runs in ‘break on all exceptions’ mode and then return to the ‘normal’ settings. This is possible in VS2003 but not in VS2005!

Tool : Add string as resource

I found this really nice little to add a string as a resource. You just select a string in the editor, right click to get the context menu and select to add it as a resource. You then get a dialog in which you can specify the key value and the resourcefile the string should be added too.

In most code I produce I use the string resource generator tool. But this little tool is a very nice addition although I prefer the type-safety that the string resource generator provides.

Browsrcamp helps testing your design with Safari

Today I was reading the website statistics with Google Analytics. It shows that about 2,5% of our visits come from Safari. I only tested our design with Internet Explorer and Firefox and it looks great on those browsers.

I remembered a website which could do a page request, render the results in Safari and present it to you as a jpeg. I googled for test safari and the first hit that showed up was Browsrcamp. Really an excellent developer tool if you don’t have access to a mac with osx.

Change mssql isolation level to read uncommitted data

Sometimes you are debugging an application and want to query the database while the database connection still has not committed (or rollbacked) the transaction. So you fire up the query analyzer just to find out that you cannot see the modifications yet (ofcourse). Today a collegue of mine (Frank Bakker) found out that it is possible to read uncommitted data by altering the isolation level on a connection.


When you have executed this statement you can now see all modifications that are still in a transaction. Isnt that neat or what?

The thing is that I used this some years ago in some functionality that generates reports based on website visits. The query did a select statement and it wouldn’t be bothered if some additional records would have beed added to the table. You can get this behaviour by adding the keyword NOLOCK like the following example.

SELECT count(*)
GROUP BY MyCoolColumn

So NOLOCK and SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED are the same but the first (NOLOCK) is usualy best option as it is directly visible that the query needs a different isolation level. Setting the isolation level seperately can ofcourse increase readability is your query does a lot of joins though.

You can also do this in MySql in almost the same syntax as shown below.

SELECT count(*)
FROM MyTable(nolock)
GROUP BY MyCoolColumn

Happy ‘reading’…

Subversion troubles "PROPFIND request failed on ‘***’ ‘***’ path not found"

I created a repository at today for the website I created with a friend for the volleybal club. We really needed version control because we are both working on the project at the moment plus that I really don’t like all those *.old *.old2 *.old3 files hanging around 🙂

So I committed the various data of the project to the subversion repository and after that wanted to branch it to identify the site that is currently live. I started the command prompt and use the svn copy action to tag the current development branch.

svn copy
https://*/yumwebsite/branches/v0 -m “Version 0”
After running the command it failed with the following output:

svn: PROPFIND request failed on ‘/yumwebsite/!svn/bc/2/branches’
svn: ‘/yumwebsite/!svn/bc/2/branches’ path not found
My first thought was that the was at fault but quickly I realised that wasn’t the case. So started googling what I was doing from. The problem was that the folder ‘branches’ really did not exist just as the error said. But somehow I blocked that error message in its exact form. So after adding the branches folder the the project root the copy action ran error free. The stupid thing is that I had the same behaviour a while ago. So I decided to post this for my own convenience in case I forget it again.

Website design not my favorite hobby

Although I am an ict nerd and resulting affection for bitfucking and neverending refactoring I also do some sports. I play volleyball and the current website of my volleybal club yum lacks some general design that works correct on both firefox and internet explorer. I’m a member of this club for some years now and I didn’t like the design from the start. So while a friend said he was working in his spare time with a redesign of the website internals I proposed to help out. I don’t know why I said that because now I’m screwed 🙂

My main objectives for the site are:

  • No tables for the websites design.
  • Crossbrowser.
  • Not too much graphics.
  • No frames.
  • XHTML proof
  • CSS validation proof

So I made a design by hand with my *excellent* css and crossbrowser knowledge (%$*@ crossbrowser makes me insane!) and within a few hours I had a design I could live with as a first draft for reviewing. I ofcourse lied a bit about my css knowledge as I”m a ‘back-end boy’. I like to play with photoshop but really lack the skills of creating a good gui or website design. The current version looks quite ok if you don’t mind that I judge my own work. Below some WIP screenshots of the design.

Version 1 Version 2 Version 3 Version 4

Below the proof that my website is non CSS friendly.

Version 4

Don’t use viewstate compression! Use http compression instead!

Just google a bit with the keywords compression plus viewstate and lots of articles are to be found about this subject like this one. The problem is that in most situations programmers are doing something that the webserver already can do for you. Not only does it compress the viewstate, it compresses all (dynamic ) documents that you configure it do to. It becomes even worse when the webapplication compresses its viewstate and the webserver compresses the rendered page output *again*. Seems a bit inefficient to me 🙂

So let the webserver do in what it is good at. Serving/streaming rendered documents to the browser in the most efficient manner. Just configure it so that it is also compresses dynamic pages. If you dont know how to do this then just google on http compression iss and lots of articles that explain how to achieve this. It really doesn’t need an extra article from my hand 😉

One situation in which it could be of interest is when an http 1.0 browser performs a request which does not support gzip compression. This way you can achieve nice results by compressing the viewstate. But in the article mentioned at the beginning of the page can be read that the viewstate would sometimes be larger then 1 megabyte. Well if that is occuring in your application then the viewstate data must be *really* expensive to calculate or read from a store must it be that important to add as viewstate data. In most application retrieving data from a data source actually performs very well although it always depends on the total count of page request, the total amount of webservers in a farm and the number of databases as is the kind of state required for some functionality.

The && and the & operators

Today a collegue had me flabbergasted by using the & operator in a boolean comparison like the following example.

return x & y;

Both x and y were booleans and I said “Hey you just forgot an &! A single & is a bitwise operator.”. And he responded that this would work but that the behaviour of a single & is that it is not lazy evaluated (short-circuiting).

My knowledge about the csharp language is quite good as is my knowledge of the .net framework so this was quite a surprise!

The funny thing is that the msdn documentation about the & operator doesn’t say anything about lazy evaluation while the documentation about the && operator also mentiones the & operator with boolean operands.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta