Please Support Andy!

Andy is playing in the Macmillan Cancer Care Longest Day Golf Challenge on June 14th. The Challenge is to play 4 full rounds in one day.

The team will drive off at first light and don’t expect to finish much before sunset. They will walk over 20 miles and hit over 300 shots each.

If you are interested in supporting this worth cause, please visit the sponsorship page here.


C# – Calculating the Absolute path of an HTML Redirect

I’ve been writing a little program that has to get some information from a diagnostic page on an embedded device. There is no password configured, but you still have to go through the login page to get a session. The device uses the rather antiquated “HTML refresh” method of redirecting from the login page to the page you originally requested.

The redirection is in the form of a relative url, ie “../../diagnostics/streams.cgi“. I needed to convert this into an absolute path to make the next request.

This is not ASP.NET, just a plain old windows forms app, so I’m using HttpWebRequest and can’t use the normal ASP.NET tools for dealing with the paths. I could just hard code it in this situation, but I hate doing that. I knew that had to be a “correct” way of dealing with it. Eventually I found out about the System.Web.VirtualPathUtility class and I thought I was home and dry. It appeared that the VirtualPathUtility.toAbsolute(VirtualPath, ApplicationPath) was what I needed. However, that doesn’t seem accept relative paths that take you back to the root. I kept getting the error “The relative virtual path ../../diagnostics/streams.cgi is not allowed here”. No indication of why – just that it’s not allowed.

Finally I spotted the VirtualPathUtility.Combine(absolutePath, relativePath) method. This was what actually worked for me:

(request is the original HttpRequest that returned the redirect)

String url = VirtualPathUtility.Combine(request.RequestUri.AbsolutePath, redirectUrl);

I hope this will help someone as my Googling revealed that a lot of people had given up looking for this and had hand-crafted their own solutions to the problem.

Where have my network icons gone in Windows 7?

If you have multiple network adapters or you frequently do a lot of network setting changes, you may pine for the nice little network status icons that were in windows XP. Today I’ve been reconfiguring a bunch of CCTV transmitters that involved rolling back firmware in the devices. Every time you do this, they reset to their default IP address. Needless to say, this is on a completely different subnet to the one they were configured on, and it’s also different to the one I need to change them to.

I’ve lost count of the number of times I’ve changed the IP address on one of my network cards today. Anyway, partly through the job I got sick of the long winded, dumbed down method in windows 7 and installed a little bit of freware called “Gab Net Stats“. This gives you a network status icon which gives you instant access to the network configuration for any of your connected network adapters.

It’s only one icon for every network adapter, rather than one per adapter as in XP, but it’s still a lot quicker and easier to get to your netwok configuration than the standard windows 7 method. It will only be useful for fewer than 0.1% of windows users, but I’m keeping it!

Where has telnet gone in Windows 7?

People who have upgraded from Windows XP to Windows 7 may have suddenly realised that Telnet no longer works from the command prompt. If you need to do a simple task that requires telnet, this is particularly annoying. The good news is that it’s still there – it just needs enabling.

Open up Control Panel and go to “Programs and Features”. Select “Turn Windows Features On or Off”. In the list, towards the bottom at the top level, is a check box for “Telnet Client”. Simply select this check box and click “OK”. Telnet will now work from the command prompt.

Generating PDF documents From C# Code

I recently had a requirement to convert an outlook calendar file into a printable diary. It was fairly easy to export the calendar into a format readable by C# code, but I didn’t expect it to be so easy to dynamically generate a PDF booklet from this data.

I looked at a few PDF toolkits based on suggestions on this page but by far the best in my opinion was PDFSharp. It simply allows you to dynamically create a PDF document, add pages to it and to draw or write whatever you want at any position on the page.

I managed to write a program that looped over my dataset and outputted separate odd and even pages (one per week) in a one (admittedly long) evening.

It would be a really good tool for any problem where you have to generate non-standard reports or documents from a data set, where you need complete control of what goes on the page. I must admit that I’m quite keen do do more with it.


Cloning and IDE disk when all your computers now use SATA disk connectors

I’ve been recently asked to upgrade the system disk on someone’s PC. It’s an old IDE disk based computer, but has some old software on it that only works on XP and we don’t have the installation disks. An upgrade is out of the question. The only solution is to clone the system disk onto a larger drive.

I really didn’t want to do the cloning on the PC itself as I didn’t want any more risk of damaging anything in it than absolutely necessary. However, I did want to be able to use my laptop to do the job.

After a bit of searching, I found this device which is a simple IDE to USB adapter. It also comes with a power supply to the disk.

You simply plug it the correct connector on the adapter into the disc, plug in the usb to your computer and you have a new disk drive on your PC immediately.

The device is a lot better than a  hard disk enclosure as it works with 2.5 and 3.5 inch IDE/EIDE and SATA disks too.

The cloning itself is done using Macrium Reflect.

Cloning isn’t something I do regularly, but for £12.95, it was worth it for a one off. I’ve a feeling that it will be somnething I’m glad I’ve got some time in the future!


Adding Graphs into WordPress

One of the things I wanted to add to the website was a graph of the output from our solar panels. I had a quick check round and came across two good candidates for this:  easychart and Simple-Graph. Being me, I decided to try both – see the solar panel output page for the result.

Easychart can be used when you want to produce a professional looking chart and you have a fairly simple set of data to hand. Once you have installed the plugin, you simply construct a paragraph  of text which defines all of the chart parameters and insert into any page you want.

Simple-Graph is designed to graph any quantity against time. The plugin adds a database table behind the scenes and gives you a data control page to load the data. It’s good for tracking your strength or weight for example.

Both of the approaches work well for the solar data – take your pick!


Improving Windows 7 Startup Time

Recently my laptop has started to boot really slowly. It’s true that it’s got an awful lot installed on it, but it’s a pretty powerful beast so it shouldn’t be this slow.

It turned out that a lot of the performance problems were caused by my trial of Perfect Disk 12 not getting on with my ESET Antivirus program, but along the way I discovered a couple of useful tips on diagnosing boot time:

  1. The easiest way to configure what starts up at boot time is to type “msconfig” in the search box at the start menu and hit return. This tool allows you control what runs at boot (careful…!)
  2. There is an excellent resource here on how to diagnose what is taking up all of the time. Basically, you open up Administrative Tools/Event Viewer and look in Applications and Services Logs/Microsoft/Windows/Diagnostics-Performance/Operational. Everything you need to know about boot up time is enclosed within.