What’s going on Microsoft? Silverlight, HTML 5?

9 11 2010

It’s amazing how the press get hold of something, twist it a little and come up with something that simply isn’t true. Is it because they simply latch onto sound bites, or because they don’t actually understand the technology (or technologies) they talk about? They don’t understand the development community and how development works? Or could it be a case of all of the above? (I am thinking all of the above for many of them)

I have now read numerous blogs, press releases etc that claim Microsoft is abandoning Silverlight. That Silverlight will no longer be used on the PC or MAC, over the web etc, just on mobile phones…This simply isn’t true, and to be frank is somewhat of an annoyance.

Yes it is true that Microsoft’s server and tools capo Bob Muglia stated that HTML 5 will become the company’s main focus for online web applications now. (Though he didn’t help the cause in the way he made his statement). But what does that actually mean. It doesn’t mean Silverlight is to be abandoned at all, it was never meant to replace HTML 5, and it wasn’t meant just to plug the gaps that HTML and HTML 5 have left. It isn’t just Microsoft’s response to Flash either, that is seeing Silverlight in a very simplistic view, almost narrow minded, and indicates you don’t know what Silverlight is…

Silverlight is a different presentation layer for .NET applications. It allows developers to deliver highly interactive, rich and powerful applications, not just stream some video, present some pretty animation etc. You should think of Silverlight as a different front end for .NET. Of which you have already so many choices, such as HTML via ASP.NET, typical forms through .NET, Windows Presentation Foundation (WPF) etc etc.

So what about the statement regarding HTML 5 for web applications? Well, Microsoft are concentrating on getting HTML 5 right, this includes IE (by the way IE9 has been shown to be the most compliant HTML 5 browser out there, ahead of FireFox, Chrome and Safari), and within its development studios (visual studio, web studio etc). To do this, resource no doubt will have to be more focused on this area for the time being…So resource will move away from Silverlight, but Silverlight doesn’t need such a large investment or resource now, since it has matured and become a full fledge part of the .NET family.

HTML 5 support

HTML is the interface to websites and web applications, and it seems to me that the press and many blog writers don’t understand this. Do they realise that ASP.NET v4 delivers HTML to a web browser? So Microsoft concentrating on HTML 5 is expected. ASP.NET (no matter your flavour of it) will need to have the capabilities to deliver HTML 5 web applications, so Microsoft needs to concentrate on this. But does this mean they are ditching Silverlight, no of course not. Did the creation of Silverlight mean Microsoft walked away from HTML presented content with ASP? Did it mean we no longer have win forms of WPF? No, of course not….Yet Microsoft were not exactly moving these along rapidly were they…

No Silverlight 5 for the moment

Some are pointing that they haven’t seen any indication of when Silverlight 5 will be available. All I can say to that is, “How many versions do you expect?” The complete .NET platform is only at v4.0. Silverlight has gone through a rapid development and period of evolution, moving quickly from v1.0, through to v4.0 now (in just over 2 years!). The latest version of Silverlight brings it in line with the .NET family, so Silverlight needed to go through a rapid development phase to catch up, it was a long way behind…

Silverlight as Windows Mobile 7 development platform

Yes, Silverlight is the development platform for Windows 7, and that’s great news to the development community. The fact that Silverlight development focus at the moment is being switched to the mobile platform is again, not surprising. After all, Silverlight has gone through rapid development on the computer. Microsoft has worked hard on tools, templates etc for developers to be able to create powerful desktop (OOB) and RIAs using Silverlight. So, it now needs to do the same for the mobile platform. Microsoft need to make it as easy as possible for mobile developers to quickly deliver powerful mobile applications, so concentrating on Silverlight tools for mobile is obvious…

Yet again I feel the press, and bloggers, don’t understand the importance of this. Silverlight is Silverlight, on the mobile and or on the web, it is still the Silverlight technology, the only difference is on the mobile, we have to follow some stricter rules about our UI and we get different tools and templates to use. Why? Well we have restricted UI space, and we need to be able to allow the user to bring up the keyboard etc etc. It isn’t an alien world, Silverlight on the mobile to developers. It is Silverlight. Just like the managed code behind in Silverlight is not alien .NET, rather it is .NET. This means developers can develop applications for multiple platforms, PC, Mac, Phone, without leaving visual studio, without learning new techniques, without learning new syntax etc. This is great, and because of this Microsoft maximises the number of developers who potentially can develop for the desktop, web and mobile…..

Withering Silverlight? Don’t be stupid…

Well obviously no…Silverlight simply won’t be going through so many quick iterations as it is now in-line with the .NET family. Microsoft are now concentrating on Silverlight mobile templates and tools and ensuring the mobile world for Silverlight developers is just as rich as it can be on your PC.

Concentrating on HTML 5 is a good thing, Microsoft has always been committed to HTML 5 and as HTML 5 slowly gets closer, Microsoft needs and wants to be at the forefront. Web applications will be delivered in HTML 5, that has always been the case. Just like ASP.NET web applications deliver HTML 4 at the moment. Silverlight will still be used on the web to plug gaps HTML 5 cannot fill, it will still be used (and will be more and more so) in an OOB (out of browser) state, effectively providing desktop powerful applications over the web and no doubt will continue to grow.

Silverlight is now a full part of the .NET family, it has caught up, and the .NET family will continue to be the core Microsoft technology for all devices…

Bing Maps getting Silverlight

4 12 2009

Well it had to be just a matter of time before Bing Maps started using Silverlight to deliver the richest mapping experience on the web. Since the start of November I have been playing around with the Silverlight Bing Maps control which far out-performs the AJAX control and for me the HTML version on the actual Bing website.

The payoff

Microsoft's Bing

Microsoft's Bing

Well for the end user, the Silverlight experience is far smoother and allows you greater control. For example zooming into an area on the map using the wheel of your mouse is a nice touch, but the app renders smoothly. In addition you can mesh together traditional map views with aerial photos. There are also nice features such as the street side walker – which currently isn’t available in that many areas, but it allowed me to jump into the map and then walk around parts of the world I have never seen (well visited now….).

With the Silverlight version, everything just feels so much more professional, it’s a real jump forward in terms of the functionality that is capable and the experience it provides the end user. Why not see for yourself, you will need to have Silverlight installed. http://www.bing.com/maps/explore/ NB If you don’t have Silverlight installed I suggest you get it asap.

Microsoft has also followed on a trend of offering “app stores”. A new application gallery will be available allowing developers to include their own information on a map.

The biggest pay off though is the capabilities this provides to other developers and websites that want to use mapping technology. I have already seen a number of demonstrations showing how you can overlay / highlight “areas” within a map. One great demonstration shows the New York marathon route, it not only shows you this route and the “area” covered on the Bing map, but also shows runners moving along the route – comparing their relative times etc….Not bad….

The .NET framework…

I have to say that I like the way Microsoft is going, building everything on the .NET framework or a subset of it. It allows more powerful applications to be built and integrated with each other. This is another great example – Silverlight, which is a subset of .NET with a WPF subset as a presentation layer, combined with the Microsoft Live web services (again delivered in .NET) delivering a feature rich experience for users. More importantly though, working in this way provides the development community with the tools they require to take things further.

By combining the Silverlight Bing Map control with the Microsoft Live web services, it is now a quick and rather simple(ish) task for any .NET developer to deliver powerful mapping / mapped based services to clients that look and perform great.

Silverlight EPOS?

14 09 2009

Now this maybe a little left field, but I have been talking to some EPOS people who have been asking if we can expect EPOS systems delivered in Silverlight. Funny enough, I have also seen people searching my own blog on this subject…

So what is the chances? To my knowledge there isn’t anyone attempting this, and there are a number of reasons why not. I have to say the chances of getting a Silverlight EPOS system are at best, very slim.

Why not?

Many EPOS systems (especially the entry level solutions) are built to work and run a physical till (cash draw and receipt printer). EPOS systems are often a single install, with your back office staff basically having the same software installed that will drive your front office point of sale terminal (till). To drive a POS terminal, the software has to interact with drivers that are actually installed on the physical machine.

Silverlight in essence is a web based technology, and as such cannot interact with drivers etc on the host PC. This is purely due to security. If you are not technical and reading this, just think, if a website could easily take control of programs and drivers on your PC, what sort of damage could a malicious hacker / developer do?

Wait, don’t get turned off just yet…

Though Silverlight couldn’t be used to drive a POS terminal, .NET applications built using WPF could, and these look and feel just like Silverlight applications. I know this means a client installation (which Silverlight avoids) however, on the POS you have to have a number of drivers and applications installed in any case.

Don’t think though that you have to use traditional thick client applications for your back office staff. Though most EPOS systems use the same software for front and back office (especially smaller solutions) it doesn’t mean this has to be the case. A division of my own company, workFile EPOS, delivers a thick client POS application, written in .NET, but back office users use the system delivered through a browser (thin client), removing any requirements for installations in the back office or indeed (if required) machines at home for home use.

EPOS systems that split front and back office functions can easily provide more flexibility, in terms of both user experiences administration flexibility. At workFile EPOS we have been looking to replace a number of web pages with pages using Silverlight to deliver a richer experience. The thin client sales agent is a prime example, delivering a “sales” interface without the need to drive a till or any hardware.

Silverlight EPOS is go…

In conclusion, yeap you can have a Silverlight EPOS solution. The chances of you seeing one shortly though are slim, and there is no chance of you using Silverlight to deliver a POS terminal. Also think that many EPOS systems were written many many moons ago and still don’t really take advantage of thin client technology or in some cases newer versions of Windows (I have seen many that still run on DOS!)

But, all this being said, some EPOS providers out there, like workFile EPOS, have the potential to use Silverlight to deliver EPOS back office functions, which bring together all the benefits of EPOS with those of rich end user experiences. If the demand is out there, no doubt Silverlight will be used for back office EPOS systems and WPF for the POS terminal experience. We shall see…

Automating Microsoft Word with .NET

7 07 2009

Well this week I was in the technical world and getting my hands dirty. A couple of our products seamlessly integrate with Microsoft Office, which works great for the business at the end of the day. So because of this we have our own technical service that effectively acts as the service that integrates with Word. However, something a little different was required. A client required us to automatically generate ordering catalogues, and we are talking word documents with around some 200 pages. This automation would happen within our LOB .NET application.

Their formatting was very specific and in some cases dependent on the type of products being added to the catalogue. Because of this, there isn’t the typical option of using bookmarks and or data fields within a template, especially as I wanted to use a single generic template for all their catalogues (they have 5 which they produce every 6 months)…


Referencing the Word Object Library

This is quick and easy, and I am presuming you know how to use Visual Studio. In your project choose to add a reference. Select the COM tab, then make your way down to “Microsoft Office 12.0 Object Library” (Your version depends on your version of word installed on your machine).


Referencing Word from .NET

Referencing Word from .NET

NB: Notice once you have added this you will have two references in your project to Microsoft Word. Look at the path and you will see they have 2 different locations, one of which is within “Microsoft.Office.Interop.Word”


Imports statement

Its good practice to import in the namespace you are working with into your class. So at the top of your class add the imports statement (VB.NET):

Imports Microsoft.Office.Interop


Opening a word document / template

Some posts talk about how to create a word document on the fly. This is great, but it’s much better and easier, if you have a document to work with from the beginning. A template is great as you can then utilise your own styles from within that document from your .NET code. In my own case, I created a word document that contained only a table of contents and a second page. The document is blank, but does consist of some customised styles that I have created. Also, our template is stored within our workFile ECM repository, so I can grab a copy of the template from the repository anytime with our application and use it.

You will need to create a Word.Application object in your code. I like to set up a module variable that holds my word application object and my word document. In addition I choose to open the word document in its own procedure, again coding practice. Also remember I am inserting this code into an already existing word service layer that we have written ….

Private Sub openWordDocument()
        'check if we have an active word application object
        If myWordApplication Is Nothing Then
            myWordApplication = New Word.Application
        End If
        'set the word document
        myWordDocument = myWordApplication.Documents.Open(myWordDocFile)
End Sub

MyWordDocFile in this case is a string value, which is the location and name of the document I wish to work with.


Inserting a paragraph, text and style

Now if you don’t have the luxury of using bookmarks or data fields, simply because you are not sure what text you are inserting, you are going to need to create paragaphs, text lines and give them some form of style.

Creating a paragraph object is easy, however, make sure you are inserting it into the document where you want. Typically this will be the end of your document as you are appending to it. Remember in the code below, myWordDocument is the actual word document itself we opened earlier.

Public Sub insertParagraph(ByVal pText As String, Optional ByVal pStyleName As String = vbNullString)
        Dim para As Word.Paragraph = myWordDocument.Content.Paragraphs.Add(myWordDocument.Bookmarks.Item("\endofdoc").Range)
            para.Range.Text = pText
            para.Range.Style = pStyleName
        Catch ex As Exception
            Throw ex
            para = Nothing
        End Try
    End Sub

Points to notice here.

  1. A paragraph is a “range”, if you like, a selection within the word document.
  2. We simply set the text and style value for the paragraph
  3. Insert a paragraph after so we are again at the end of the document and working in a new paragraph. (next time we call this method)
  4. I choose to marshal out of memory the paragraph object. This is because it is a com based object and as such we can get some memory issues and weird errors being raised by the dll when dealing with larger document generation.
  5. I use the garbage can to ensure everything is cleaned up properly (this isnt over the top, as without it I received error messages for larger documents – such as “The callee refused the call”. Nice…)


Inserting text in a range without a new paragraph

If you simply want to add text and dont want to create a new paragraph, then again, you need to create a range, however this time it is just a range (not a paragraph).

Public Sub insertTextLine(ByVal pText1 As String, ByVal pText2 As String, ByVal pText3 As String)
        Dim textPart1 As Word.Range = myWordDocument.Bookmarks.Item("\endofdoc").Range
        Dim textPart2 As Word.Range
        Dim textPart3 As Word.Range
            textPart1.Style = "BookTitle"
            textPart1.Bold = True
            textPart1.Bold = True
            If pText2 <> vbNullString Then
                textPart2 = myWordDocument.Bookmarks.Item("\endofdoc").Range
                textPart2.Bold = False
                textPart2.InsertAfter(" " & pText2)
            End If
            If pText3 <> vbNullString Then
                textPart3 = myWordDocument.Bookmarks.Item("\endofdoc").Range
                textPart3.Bold = False
                'two tabs to the correct location
                textPart3.InsertAfter(vbTab & pText3)
            End If
            'insert a new paragraph...
        Catch ex As Exception
            Throw ex
            If Not textPart1 Is Nothing Then
                textPart1 = Nothing
            End If
            If Not textPart2 Is Nothing Then
                textPart2 = Nothing
            End If
            If Not textPart3 Is Nothing Then
                textPart3 = Nothing
            End If
        End Try
    End Sub

What we have done here is effecitvely appended 3 text values into a single text entry within our word document. Notice that by using “InsertAfter” from our Range object, we are literally inserting text, no paragraphs. Also I have used vbTab to space out the value. My word document has a set location for a tab entry within the selected style, this ensures I know where the text will be inserted in that line.

Again ensure you clean up your objects and marshal them out of memory.


Saving your document

In my case, we are working with a temporary file that has been copied locally from the workFile repository. You may be working with just a template though sitting on your hard drive somewhere, so make sure you dont save your document over the top of that template! School boy error if you do…..

Saving the file is real easy, provide your directory and file name and you are almost complete:

Public Sub saveCatalogue (ByVal pCatalogueName As String, ByVal pCatalogueLocation As String)
        If Not System.IO.Directory.Exists(pCatalogueLocation) Then
        End If
        myWordDocument.SaveAs(pCatalogueLocation & pCatalogueName)
    End Sub


Tidy up memory and word

Your file has been saved, but you have yet to finish. If you look in task manager you will notice that WINWORD.exe is still running, and its memory size could be quite large. If you don’t kill this off correctly and you continue to create word documents in this fashion you will cause havoc with performance. So, we have to clean up after ourseleves.

    Private Sub closeWord()
        On Error Resume Next
        'quit the word application
        'marshal out the com objects, dont want any memory leaks here...
        If Not IsNothing(myWordDocument) Then
            If Not IsNothing(myWordDocument.Fields) Then
            End If
        End If
        myWordDocument = Nothing
        myWordApplication = Nothing
    End Sub

Quit word then clean up….Again we are marshalling out objects from memory and cleaning up everyting.


Using fields

If you have the luxury of knowing the format of the document (such as populating an invoice, a letter etc), then you can use fields to make life a lot easier for you. Again, set up a template word document with the content you desire. For that content which is to be added dynamically, insert a data field. (See help within your version of Office to do this).

From .NET when you have the document open, you can now loop round or search for those fields on the document. Fields are found within the word document object itself, and is a collection of Word.Field objects.

You can then update the field text and carry on….See the sample line of code below, which is using an invoice reference to insert into the data field.

field.Result.Text = CStr(invoiceRef)



Word is great to automate and can be very powerful for your .NET applications. Sometimes you may struggle to find great documentation on this, however, its worth searching for…Just remember, always clean up your code and look after your memory, if you dont, you will get some weird and wonderful error messages once processing larger files…