Web Design
Parsing Google Maps HTML
If you cannot afford 10 grand for an enterprise version of the Google Maps API, then you might be stuck having to parse the html form the clunky old maps.google.com website. If that is the case, here’s a snippet of code that seems to work consistently to parse out the lat and lon from the html.
 If HTML.Length > 0 Then ‘we have something back so ‘get important part of string Dim s1 As String = geo.Substring(geo.IndexOf(“viewport:{center:{“), 200) Dim intStartPos As Integer = s1.IndexOf(“{lat:”, 0) + 5 Dim intEndPos As Integer = s1.IndexOf(“}”, intStartPos) Dim intCommaPos As Integer = s1.IndexOf(“,”, intStartPos)
‘now assign the strings to lat/ lon vars _lat = s1.Substring(intStartPos, intCommaPos – intStartPos) _lon = s1.Substring(intCommaPos + 5, intEndPos – (intCommaPos + 5))
End If
Telerik RadGrid for ASP.NET
I was lucky enough to get a great deal on the RadControls for ASP.NET by Telerik recently.
I’d been looking at their RADEditor offering as a replacement for my Content Management System rich text editor. The editor looks awesome and supports lots of browser versions, whereas my editor only works in Internet Explorer (its quite old now(the editor not IE)).
Anyway, I leaped into the RADGrid and began to put it into a project but stumbled upon a problem where I couldn’t get an event to fire. This has been quite a pain in the butt! I finally worked out the problem a few days ago and wanted to share it here in case anyone has a similar issue.
The RADGrid is fantastic and very powerful. It is in fact, huge in terms of it’s functionality and capabilities. After I’d got the grid loaded with data, I wanted to edit a row and save that data or add a new row. At this point I had a problem where I couldn’t get the some of the grid editor events to fire. Specifically the Update and Cancel events of the edit form.
You can find the full post and responses at the telerik forum.
I had thought it was maybe a ViewState problem, which it turned out to be. Even though I had enabled viewstate in properties I found I had to explicitly enable viewstate in the asp.net tags of each form, usercontrol and control that was in the loaded control hierarchy.
It works like a charm and I’m very happy with the results. I’ve only just scratched the surface and I’m looking forward to developing more solutions with this control.
Essential Objects – Treeview
I’ve just finished a web project that I used the Essential Objects TreeView control.
I had thought initially that it would be relatively easy to configure. I’ve used a number of Essential Objects controls before and always found them fairly intuitive to use.
However, the TreeView was anything but intuitive. At the designer level it looks pretty straightforward. Just like the Tabstrip I thought. And initially all seemed well. But I had a real problem making sense of the data binding. Of course, its data driven so that would be a problem.
I thought I’d got it sorted out fairly early on, and then I realized that the data binding of each node was not what I expected.
The programming examples for the Treeview are, unfortunately non-existent on the essential objects website. Instead, they refer you to the menu control examples. This was pretty frustrating, as I was on a tight deadline and just wanted a Treeview example, nice and straight forward like. Please feel free to post this if you want.
So, this is how I bound the Treeview and got the correct itemID’s established.
Private Sub tvCookClass_ItemDataBound(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles tvCookClass.ItemDataBoundTry ‘set the itemid based on the dataset array index e.NavigationItem.ItemID = CType(e.NavigationItem.DataItem, DataRow).ItemArray(0).ToString If e.NavigationItem.Level.Equals(1) Then ‘this is the student level data ‘position 4 is the class data for each payment e.NavigationItem.Value = CType(e.NavigationItem.DataItem, DataRow).ItemArray(4).ToString End If Catch ex As Exception End Try End SubÂ
One really neat feature is the customItem control. This allowed me to quite easily embed an editor feature inside the Treeview. This was a relief after the problems I had binding the thing in the first place.
This is what the maintenance list looks like;

This is what the editor looks like. You just click on the row to display the editor.

So eventually I got a pretty neat solution using this control. It will require some work to get the thing looking a little better. I might even look at changing the editor so it goes below the selected node, rather than right next to / over it. But it’s nice to be able to update or edit the data with a couple of mouse clicks, without posting to a different form.
I would definitely use it for other projects. I didn’t have time to put it into an AJAX wrapper but next update I’ll try that too.
Visual Studio 2005 Upgrade
When I first installed VS 2005 I did so with a version prior to SP1. This created a problem for me when I tried to upgrade a project from VS2003 to VS2005.
I didn’t know that Microsoft had created a new “website” project template, which had replaced the 2003 web application.
The first point to note here is that there must have been hundreds of thousands of web applications already in existence and no doubt many thousands of developers waiting for the new release and eager to upgrade. It must have been very disappointing; well actually, very frustrating to try and upgrade and find out that your good old reliable web application was superseded by a “website” project.
This is one of the things that really annoys me about Microsoft. They are so eager to make the tools available to anyone with half a brain and an inkling that they might be able to program or develop systems. What they end up doing is trying to hide any levels of complexity to make the tools easier to use. This is not always a bad thing, hell, I don’t want to go too low level, I’m not that smart! But, they created a new website project template, trying to make the tool easier to use and at the same time, seem to have thrown the old web application model away?
Anyway, the web application model was provided by a plug-in (snicker) and in VS2005 SP1 it’s actually a template.
So, after an initial attempt and then looking at the ensuing mess (web application upgraded to website project; believe me, that isn’t a pretty sight!), I was able to upgrade fairly well after installing VS 2005 SP1.
I really had few problems after that. Quite a few warnings about obsolete syntax errors, which I updated in short order.
One interesting problem that did arise was trying to debug the project after conversion. I obviously changed the web server settings to use .NET 2.0 instead of 1.1. I then couldn’t debug the project until I had setup a separate application pool for the wp3.exe process. It seems you can’t run the old .NET 1.1 and .NET 2.0 processes side by side in the same application pool.
So I’ve been developing a new system in VS 2005 and have immediately found the new master page addition to be extremely useful. I’ll explain that in a future post.
Visual Studio, SQL Server et al upgrades…
So its been a fair while since my last blog post and boy have I been busy. Here are a few items that I have to write about soon, so as not to forget what the hell it is I’ve been so busy with lately.
- Upgrade to Visual Studio 2005 (yes I know this may seem long overdue but I think my timing is about right)
- Upgrade to SQL Server 2005
- Upgrade of an existing ASP.NET project from VS 2003 to VS2005 (man, I can’t believe what a pain in the arse this has been)
- System development update. Its been a busy month, as you can probably tell…
Well, the good news is that I’ve done all of the above and everything is working well.
The upgrade to SQL 2005 was fairly straighforward actually and yes, I’m running both SQL 2000 & 2005 happily on the same server.
The Visual Studio upgrade was less than satisfacory. Especially as I installed a version pre SP1 and then found that VS 2005 pre SP1 had a totally different concept of what the structure of a web project should be, so when I tried to upgrade an existing project from 2003 to 2005 the result was an utter mess. I then found that the in order to create a VS 2003 project in 2005 there was an add-in? A freakin add-in Microsoft? WTF?
I then found that VS SP1 had the add-in built in (YEY! Way to go MS!), so I ripped the offending pile of cack that was VS2005 pre SP1 off my PC and installed VS 2005 sans SP1. This was much more satisfactory.
I then opened an existing project and it coverted into what resembled an ASP.NET web application. I don’t know what MS was thinking when they created the new website project (well, actually I do and I’m going to save that rant for another post).
Anyway, I now have VS2003 and VS2005 IDEs installed and happily co-existing, which is a real plus. Also, the SQL Server 2005 client tools, which used to be called enterprise manager, are installed on the same PC as the old Enterprise manager and they both work fine. The bset thing is that I can use the new SQL 2005 client tools to administer both 2000 and 2005 databases, good stuff.
I’ve been putting this off for as long as possible, but had to bite the bullet mid 2007 as VS 2008 and associated .NET platforms will be with us soon and I didn’t fancy the idea of ugrading from Visual Studio 2003 to 2008 (nightmare!)
Bulletin Boards / Membership Site Systems
I’ve been looking at some bulletin board systems recently. I want something that I can easily integrate into existing sites and new sites that I’m putting up.
I looked at phpBB which has been around for a while and seems to be well liked. It’s also free, which is nice… I was toying with the idea of that and then looked at vBulletin, which is another that is highly regarded, Mark Joyner uses it so it’s good enough for me! It costs $180 for a site license, so it’s not too bad price wise…
Both of these are PHP systems with mySQL on the backend. Then I looked as some ASP systems. Web Wiz Forums looks pretty good and megaBBS gets a lot of good reviews too.
There’s also a WordPress plugin called bbPress that looks OK. Seems like it might be in fairly early stage of development though.
Anyway, I’ve got a number of systems running PHP on Windows 2003 with mySQL on the backend. No problems there, but PHP isn’t a language that I develop in, so I’m really looking for ASP or ASP.NET.
If you have any recommendations or experience of these products, or others that you know of, please let me know…
Thanks Steve
Oh, look what I found here at Wikipedia for ASP Forums and PHP Forums and this is a review site I was looking at earlier.
How To Use .NET Cookies
If you want to access, read, write or otherwise store and send cookies in .NET you will need to access the request objects cookiecontainer. Once you have that in your sights, you can grab the cookiecollection and pick up the cookie that you need.
Here is an example;
Dim req As HttpWebRequest = CType(WebRequest.Create(http://urlgoeshere.com, HttpWebRequest) req.Method = “POST” req.CookieContainer = New CookieContainer ‘get the response Dim res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse) ‘now get the cookies res.Cookies = req.CookieContainer.GetCookies(req.RequestUri) Dim ck As System.Net.Cookie = res.Cookies(“CookieName”)
Once you have the cookie, it’s simple to add it to your request
‘add the cookie to the request req.CookieContainer = New CookieContainer req.CookieContainer.Add(ck)
So if you ever need to grab a cookie and then use that cookie in another request for authentication purposes, thats what you do…
Dataset.ReadXML or ‘O Schema, Where Art Thou’
I’m still cranking ot XML by the bucket load and ran into an interesting solution to a problem using the datasets and readXML.
I wanted to use datasets rather than XPath or XMLDocument or any of the other readers. However, I was having trouble mapping the XML schema to the dataset paradigm in my mind. So I found this niffty piece of code and tweaked it. It helped me a lot!
Public Sub PrintDataSet(ByVal ds As DataSet)
‘ make an output file for the schema
Dim fn As String = Request.PhysicalApplicationPath + “\theOutputfile.txt”
Dim dw As StreamWriter = New StreamWriter(fn)
‘ Print out all tables and their columns
For Each table As DataTable In ds.Tables
dw.WriteLine(“TABLE ‘{0}’”, table.TableName)
dw.WriteLine(“Total # of rows: {0}”, table.Rows.Count.ToString)
dw.WriteLine(“—————————————————————”)
For Each column As DataColumn In table.Columns
dw.WriteLine(column.ColumnName + “: ” + column.DataType.ToString())
Next ‘ For Each column dw.WriteLine(System.Environment.NewLine)
Next ‘ For Each table ‘ Print out table relations
For Each relation As DataRelation In ds.Relations
dw.WriteLine(“RELATION: {0}”, relation.RelationName)
dw.WriteLine(“—————————————————————”)
dw.WriteLine(“Parent: {0}”, relation.ParentTable.TableName)
dw.WriteLine(“Child: {0}”, relation.ChildTable.TableName)
dw.WriteLine(System.Environment.NewLine)
Next ‘ For Each relation dw.Close()
End SubThe output file looks like this xmldatasetprint.txt, which, believe it or not, makes a lot of sense too me
Posting XML using .NET
Well, I’m into the new xml project somewhat now and have created the xml output file and the code to post it using .NET. If you are unfamiliar with the procedure, here is a sample.
‘first we create a request Dim req As WebRequest = HttpWebRequest.Create(http://www.trstechnology.com)
‘set the request method to POST req.Method = “POST”
‘now encode the xmlout as byte and write to ‘the request stream for posting Dim xmlout As String = “this is the xml text that you want to POST” Dim encoding As New System.Text.ASCIIEncoding Dim byte1 As Byte() = encoding.GetBytes(xmlout) ‘set the content length of the string being posted ‘create the stream amd write it and close req.ContentLength = xmlout.Length req.ContentType = “text/xml”Dim postdata As Stream = req.GetRequestStream() postdata.Write(byte1, 0, byte1.Length) postdata.Close()
‘now get the response Dim res As WebResponse = req.GetResponse ‘read it into a stream and close Dim sr As New System.IO.StreamReader(res.GetResponseStream) PostXMLOut = sr.ReadToEnd sr.Close() res.Close() I’ve run this against the development system and we are getting a timeout error, which the vendor is looking at. Should be pretty straightforward though…It get’s a bit more involved if you want to POST the data asynchronously, or read the response asynchronously. But we don’t, so HA!Hope this makes sense…
The Joys Of XML
I’m currently working on a project that requires posting and reading response online using XML. I’m not talking about web services here, it’s a plain old POST of an XML file, response is returned as copious amounts of XML, read that and build a web form based on the contents (yawn), have website user make selections and POST that back as plain old XML, get another response back as, yep you guessed correctly, XML and read that, make a decision based on the contents and voila, we’re done.
 I’m a little bit surprised that the company that runs this service, the bowels of which I am groping around in, has not developed a SOAP API or Web Services API that can be programmed against without the raw manipulation of XML (i.e. text) data. I’ve used the Amazon, PayPal and EBay API’s and while there is a hefty learning curve it is far more intuitive, in my humble opinion, to code against an API than against raw XML.
Whenever I start having to parse text files, I don’t care if we have XSD files and a schema, yada yada ya, I feel like I’m using old technology that is cumbersome, although it does the job, right. I know that the legacy of XML and the use of text goes back a long way, when it was far more difficult, time consuming etc to open up a port and configure a firewall, so passing text through was an easy solution.
I can only guess that this company has so much legacy code and systems that the move to a SOAP API and web services infrustructure is still in the pipeline. Just as there are still tons of companies that still use EDI right?

