Tuesday, 26 January 2010

XHTML & ASP.Net - forcing HTML tags to lower case

One of our clients has set up a central database containing all their product information and has asked us to link to this data to display it on their web site.

All well and good but I can be a bit of a perfectionist sometimes and I like my HTML tags to be in lowercase so that it becomes XHTML compliant. Typically, the feed of data contains tags that are all in uppercase. Even by solving this issue, I'm not really onto a winner with this feed as the tags aren't closed off in most cases but I figure making the tags lower case is a start!

Anyway, I did start off by doing a list of replaces after the string:

strOriginalString.Replace("<UL>", "<ul>").Replace("</UL>", "</ul>").Replace("<LI>", "<li>") etc etc

I realised this could get very long and they may also start using tags that I hadn't covered so I decided a regular expression was probably the way to go. Not being a genius (or anything remotely close) with these, it took a bit of Googling and I eventually came up with a solution.I'm not sure it is the best way but it does seem to work.....First I created a function on the ASP.Net code behind as this:

Private Function ToLowerCase(ByVal m As Match) As String
        Dim objSB As New StringBuilder
        For intLoop = 0 To m.Captures(0).Value.Count - 1
            objSB.Append(m.Captures(0).Value(intLoop).ToString.ToLower)
        Next
        Return objSB.ToString
End Function

This should receive a full tag and go through each character (including < and >) and set them to lowercase before returning the full tag now in lowercase.

Finally I had to set up the RegEx on the string in question:

litText.Text = Regex.Replace(strOriginalString, "<(.|\n)+?>", New MatchEvaluator(AddressOf ToLowerCase))

This seemed to solve the issue for me. Maybe in the future I will find a quicker/cleaner way....      

Monday, 25 January 2010

Google maps embedding - who moved the marker?

All I wanted to do was have a little map next to each address for outlets on a web site. I figured this would be a nice quick job - especially as Google nicely provide an embed link when you use their Mapping site.

I knew I would have to modify the links at runtime to accept the postcode from the database I was using to list the outlets but I figured I could do this quite easily.

So let's get a single outlet done and working before I start trying to be clever.

Postcode = WA15 8ES

Go to Google maps, enter it and get the following.....



Perfect so far!

so now I get the embed link kindly provided by Google for this particular location

http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=Altrincham,+Cheshire+WA15+8ES,+UK&sll=53.800651,-4.064941&sspn=15.686479,36.254883&ie=UTF8&hq=&hnear=Altrincham,+Cheshire+WA15+8ES,+United+Kingdom&z=16&ll=53.388896,-2.34556&output=embed

Place this on my site and voila......



Easy! Erm.... actually...... who moved the marker! I've changed nothing, just done as Google suggested and embedding has moved the location of the outlet to a main road that is actually a bit of a drive away - not very useful for customers really!

Incidentally, the link they provide for this

http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=Altrincham,+Cheshire+WA15+8ES,+UK&sll=53.800651,-4.064941&sspn=15.686479,36.254883&ie=UTF8&hq=&hnear=Altrincham,+Cheshire+WA15+8ES,+United+Kingdom&ll=53.389471,-2.344573&spn=0.007716,0.017703&z=16

is fine so why the embedding is so far out is something only the Google developers could perhaps answer.

I did mess about with trying to change the values in the embed link's querystring - including the latitude and longitude values but got nowhere. In the end, I resorted to use the Google Maps API and all seems well (although I did have to use the longitude and latitude locations for this to work, rather than the postcode).

A colleague suggested that the embed link only takes into consideration the first part of the postcode. If this is true then I'm not sure why Google would have made it like this unless they are trying to force developers down the API route.

Friday, 22 January 2010

ASP Email - character positioning

Here's an interesting problem I was given.

A web site dealing with villas is written in classic ASP. When an enquiry for a property is submitted by a customer an e-mail is generated containing all the details of the enquiry.

 All has been working well until today when it crashed with a mail error. The error was as follows:

CDO.Message.1 error '8004011b'

From searching about, this seems to look like an error regarding the mail server being unavailable - or can't be connected to.

However, I knew this couldn't be the case because the same server had other sites sending mail OK using similar code.

To narrow down the issue I started stripping out the HTML from the body text of the email that was being sent. Part of the information was the arrival date and time and departure date and time from the property that had been requested. This was where I started to find a difference between it working and not working.

If I removed the departure information it worked OK, if I swapped departure for arrival information and basically replicated the arrival code (for testing purposes), it failed! What became more strange was that taking the colon our of the middle of the departure time caused the email to send, despite the fact the arrival date had it in!. Placing a colon at the end of the time also caused it to work.

So "1000" and "10:00:" both worked but "10:00" didn't. This was turning out to be quite a bizarre problem!

Upon trying random things in the code I solved the issue. There must be a character limit on the commands sent to a mail server, or at least an IIS SMTP server, and the colon was appearing at the end of a line being sent which must have given the server a problem.

The solution was to place new lines (vbNewLine) in the code above so that the HTML wasn't one big string and the mail server didn't have any issues.

I knew that dots could cause issues but colon's was something new for me.

Thursday, 21 January 2010

Vista/IE opening with no connection

For a while now I have had issues opening Internet Explorer on my work computer. The program would be opened, fail to get a connection and I would shut it down and repeat until it did connect. The home page was aimed towards a local Intranet address but this wasn't the issue - whatever the home page was set as, the same problem occurred.

Now this may have started once Microsoft ISA Server became the network's way out to the Internet as I am sure it didn't happen before. However I can't pinpoint it for definite.

As I mainly use Firefox for development of web sites at the moment I haven't really been too bothered about it. It was just an annoyance that I had to try starting IE several times before I had a successful connection.

At random intervals I did try and look into it through our trusty friend Google but to no avail.

Recently however, I found out it was happening on other computers on the network also and users were just putting up with it rather than informing me.

Anyway, I had another Google session on this last week and found this post about tabs not connecting. Now I didn't do everything mentioned on this page but simply decided to try the following in the command prompt;

regsvr32.exe /n /i ieframe.dll

Once I had done this, my IE then seemed to connect every time I started it the first time so I am hoping I have solved it.

I passed the same info onto some colleagues and one says it is now better but not perfect. I'm yet to follow it up to see if it is the same problem.

As far as I am concerned though, so far so good!


Monday, 18 January 2010

Excel file failure

A friend sent me a file that was allegedly an Excel file that she couldn't open.

Sure enough, Excel opened up when the file was double clicked and then showed nothing. To tabs, no option to do anything and no data.

I attempted to open it up in repair mode and got the same.

Strangely it opened successfully in OpenOffice so I was at least able to retrieve the data from it and re-save it in Excel format.

I have no idea what may have happened to the original file - I can only guess it was corrupted in some way.

I did find it amusing that OpenOffice opened up an Excel file that MS Excel couldn't though! I appreciate it will access the data in a different way but I would have expected Excel to get closer than it did!