views:

235

answers:

2

We want to develop addins for outlook, word and excel. As of now I am aware of 2 types of solutions. One to go for Shared Add-in (COM based) and other to build VSTO based Add-in. As I am new to this, which would be the better option? (Or if there is 3rd way,please let me know) We are targeting Office 2003 and 2007 both. And I would prefer developing this addins in C#.

+2  A: 

If you are going to be developing in C#, I highly recommend sticking with VSTO. This has a much simpler add-development framework, and works perfectly with C#.

Going the COM route, especially with C#, is just adding extra pain that's unnecessary at this point.

Reed Copsey
Gregor
+1  A: 

Not directly an answer to your question but also worth considering before starting add-in development: As already said by Reed, when developing an Office add-in using VB.Net will make life a lot easier than using C#.

A call into the Office object model typically leaves out several optional parameters. However, in C# - because C# does not (yet) have optional parameters - you will have to specify each and every of the optional parameters. Not enough, for COM add-ins you will also have to take care of boxing the arguments yourself, i.e. instead of passing a simple bool or int you have to convert it to a reference type first. All this makes code quite unreadable.

E.g. the code to open a document in Word would look like that in C#:

object objTrue = true;
object objFalse = false;
object missing = Type.Missing;
object objInputFile = strInputFile;
Document document = WordApplication.Documents.Open(ref objInputFile, 
    ref objFalse, ref objTrue, ref objFalse, ref missing, ref missing, 
    ref missing, ref missing, ref missing, ref missing, ref missing, 
    ref objFalse, ref missing, ref missing, ref objTrue, ref missing);

whereas the same in VB.Net would be much easier to read and write:

Document document = WordApplication.Documents.Open(strInputFile)

(Additional info: With C# 4.0 this will become much simpler using dynamic)

0xA3
Wow, that's really irritating! Good to know! :-)
unforgiven3