Saturday, September 13, 2008

Note To Self: Activator.CreateInstance(Type.GetTypeFromProgID(“ProgID”)) is the new CreateObject(“ProgID”)

CodeProject - Spell Check in .NET without adding a reference ahead of time - version agnostic!

“Very often, when developing software, we have to include a spelling and grammar check function, and don't want to shell out the cash for a proprietary solution. We search the web and find ways to incorporate the MS Word interop capabilities - it always starts with, create a solution, add a reference.

Then, we build it and run it, and it works great. Then, we run it on someone else's computer who either doesn't have MS Word or has a different version, and we have all kinds of problems - assemblies not found in the GAC, etc. Why can't we add the reference at runtime so we can use any version of Word?

Using the System.Reflection namespace, we can!

…”

There are a number of times, now and in the future, where I need to dynamically (i.e. at runtime) invoke a COM object via its ProgID and so this caught my eye. I know you all know this, but I am still trying to delete/re-purpose my VB6 mental pathways and when I saw this code snip in the project I knew that I wanted to capture it for future reference.

Yes, the .Net VisualBasic namespace has a CreateObject (and GetObject, etc) but as one of my personal goals is to start using C# in my personal projects…

No comments: