How do I use the Microsoft VSTO interfaces? - c#

I would like to create an addin for microsoft outlook, and am using the visual studio tools to do so.
However I am really struggling to get my head around the use of interfaces within the VSTO environment - the resources on MSDN show many useful looking interfaces, but I am unsure how to use these interfaces to access data. For example I am trying to add a new folder into an IMAP account but am finding it very difficult to work out how to get outlook to do so.
Can anyone recommend any good resources for learning how to use VSTO (I have VSTO for dummies, but it doesn't cover the level of detail I need, I have been using MSDN, but I have found it doesnt offer much information on how to use the interfaces etc.)

I suggest checking out the book by Eric Carter + Eric Lippert, "Visual Studio Tools for Office 2007: VSTO for Excel, Word, and Outlook". It covers VSTO 2007, and not 2010, but it gives a solid overview of the object model for each of the 3 major Office applications, and has some good explanations on the interfaces.
http://www.amazon.com/Visual-Studio-Tools-Office-2007/dp/0321533216

Related

VSTO add-in, access to both Excel and Word

I'm working on a VSTO add-in for Word 2010 (.NET Framework 4.6.1) in C#. This add-in is meant to produce Word documents from a template, using data from a few sources, a few of which (depending on the ) being one or more Excel workbooks.
I have been perusing the MSDN literature, but I feel as if I'm missing a crucial step.
Is it possible to access the Microsoft.Office.Tools.Word objects in the same add-in as Microsoft.Office.Tools.Excel objects? They each seem to rely on the Factory.GetVstoObject() method, which uses a factory object that is application-specific. I know I can use the normal Microsoft.Office.Interop.Word/Excel objects, but they aren't as useful.
I have been playing around with having two add-ins, one targeting Word and one targeting Excel, but I'm having a hard time getting them to see each other. If this isn't achievable as a VSTO add-in, can you reference multiple Office application object models in a standalone executable?
Is it possible to access the Microsoft.Office.Tools.Word objects in the same add-in as Microsoft.Office.Tools.Excel objects
Maybe not those exact types but you can find something similar. You can always drop down to pure COM/Ole Automation level completely by-passing VSTO APIs. Office is still exposing a COM API which VSTO I suspect is just wrapping into nicer c# classes.
e.g. from a c# Excel VSTO add-in you can fire up word document by:
try
{
var type = Type.GetTypeFromProgID("Word.Application");
dynamic app = Activator.CreateInstance(type);
app.Visible = true;
dynamic doc = app.Documents.Add();
doc.Content.InsertAfter("Hello world!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Note: I am using dynamic (one of the main purposes of dynamic in c# was to make COM easier) here so as to avoid dependence on any specific COM-type library. It's version neutral so it should work any Word version.
I know I can use the normal Microsoft.Office.Interop.Word/Excel objects, but they aren't as useful.
In what sense?
See also
Where to find OLE Automation's documentation, specifically this answer
Disclaimer I never have done any shared add-in I'm going to talk about here (#Cindy Meister would know more)
Till VS 2010 you could create a project called Office Shared add-in. Here is how it looked like in VS 2003
This would be, probably, something what you would need but as said it's no longer available and I seem to remember there were some issues with it anyway.
I found this post where the guy is trying to use something what would mimic the Office Shared add-in template. He claims it's working so that would be worth to try.
Otherwise you would have to use the Office PIA as #MickyD answered

Microsoft VSTO extension

I am looking for an extension of the Microsoft VSTO framework. I am still in the learning stages so I could be wrong, but I am finding that the capabilities that it has are very minimal. Is there an extension of this framework that is easier to work with? I'm currently looking into NetOffice, but it seems like it's more for external applications using office than for add-ins.
An example of how I think it is very minimal. I wish to get the email address (stack#overflow.com) for the recipients when the user clicks send in Outlook. But the only thing available is the exchange address (/O=ORGANIZATION_NAME /OU=EXCHANGE_GROUP /CN=RECIPIENTS /CN=USER_NAME). This function is available here, but this seems like it should just be available in the VSTO framework.
Thanks,
McAngus
VSTO does not expose anything the Outlook Object Model does not expose. Use AddressEntry.GetExchangeUser().PrimarySmntpAddress.

Editing Microsoft Word Documents Programmatically

I want to know if this could be done.
I am building a data dictionary for our software system (school project), and I'm thinking of an automated way to do this. Basically I don't use much of Microsoft Word (2007), I only use it in documenting schools stuff, etc. I want to know if its possible to create/edit a Word document programmatically from a template.
The idea is, I will create a page on Word that contains an empty form that will be repeated on every page. For every data that I will input to my program, it will update the corresponding field in the form and skips to the next form.
The purpose of this, is to eliminate copy-paste methods (my habit) and to speed things up when doing the documentation.
Word automation, as suggested by others, will lead you to a world of hurt for two major reasons:
Office is not intended to be run unattended, so it can pop up message boxes at any time, and
It is (probably) not licensed to enable office functionality for computers which don't have it. If you generate a Word document on a web site using automation, you have to make sure that this functionality cannot be reached by computers which don't have office installed (unless they changed this rule in the last years).
I have used Aspose.Words, it costs a little, but it works well and is intended for this.
Not exactly sure what you really want, but creating word documents with c# shouldn't be any problem:
http://support.microsoft.com/kb/316384
If i find out your purpose correctly you need to visit this microsoft msdn link
Manipulating Word 2007 Files with OpenXML
Definitely possible. A fairly easy way of doing it using Office Automation. See this KB article for a basic sample: How to automate Microsoft Word to create a new document by using Visual C#
I think the main difference to that sample will be that you'll open your template and do SaveAs instead of creating a new document, but I can't remember exactly.
However, depending on your exact requirements, there might be better alternatives. For example, it's not recommended to do Office Automation on servers (including on webservers), so if that's needed you might want to look at something else.
You can use com interop of .net framework.
Understanding the Word Object Model from a .NET Developer's Perspective
Building COM Objects in C#
Using COM programming is not the best way as mentioned by erikkallen, I suggest using OPEN XML. It is really easy to use and your document generation operation will be very fast.
http://blog.goyello.com/2009/08/21/how-to-generate-open-xml-file-in-c-in-4-minutes/
http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx

Creating Outlook Email Draft via C# Application

I am in the estimating phase of a project, and one requirement is that my application will create draft emails (with attachments) in MS-Outlook, which the user can then review and send. The app is written in WPF.
The clients will have either Outlook 2003 or Outlook 2007. The files that need to be attached will already exist on the file system when the drafts are generated.
I have done some initial research, but would like to get some opinions from people who have first-hand experience.
Questions:
What tool would you use to
accomplish this?
Will there need to be separate code for Outlook 2003 vs. 2007?
In general, using whatever tools are recommended, is this a relatively straightforward problem to solve?
Thanks for any insight.
a c# wpf application should be able to do the job just fine, you just need to add the outlook libraries in your references and you can work with outlook directly from your WPF app.
I only write for 2003, but I do know that 2003 and 2007 use different libraries. There's probably a clever way check what version of outlook is being and use the methods from the correct library, but it will take some work to figure out.
It's relatively straight forward except for the security prompt you'll get if you send the email. But I suppose if they are going to have them review it first, you should be able to generate the email, open it in an outlook window for them to review, and have them click the send button.
Would you be able to use WebDAV and then simply create the message and drop it in the users' Drafts folder?
Basically, you'll end up using something like this product (or you can roll your own) to create and save the message. You might be able to find an open source solution.
I think there are a couple tools you could use here:
Visual Studio Tools for Office (VSTO)
total control over Outlook
version of Outlook may matter
Assuming you have Exchange, you could use WebDAV, Exchange's XML methodology
version of Outlook wouldn't matter here
Use the built in mailto: functionality
lots of results for using this to include attachments - Google Results
would work for email apps other than Outlook
this probably would be quickest solution, but the least control over the output
An Outlook Add-in is probably a good way to go for this application. The tool set you need is Visual Studio Tools for Office (VSTO). With the possible exception of the WPF requirement, this is pretty straightforward.
Be aware that the API's and the VSTO tools evolved between 2003 and 2007. You can potentially have a single code base but you will need to write for the least common denominator, 2003.
2003 and 2007 also have different Primary Interop Assemblies, the components that bridge the gap between your .NET code and the native code COM interfaces that Outlook has. This can be a challenge when it comes to building and installer for your add-in. If you want your add-in to install the PIA's, you need to detect the version of Office and install the appropriate version, or, more commonly, just build two different installers.
I've never tried to do WPF inside Outlook 2003. There may be some issues with it but I don't know.

SharePoint Primer

I recently started working on my first SharePoint (2007) project (C#), so I was wondering if anyone can point me to some good resources that will get me up and running with SharePoint programming basics quickly. I'd like to have a deeper understanding of the various terms I'm hearing such as Features, Lists, wsp, etc.
One of the best resources is Ted Pattison's Inside Windows SharePoint Services 3.0. Great resource, especially if you are okay with purchasing a book.
this should help
Sharepoint Best Practices
sharepoint 2007 trainning kit
http://www.microsoft.com/downloads/details.aspx?FamilyId=7BB3A2A3-6A9F-49F4-84E8-FF3FB71046DF&displaylang=en
Office SharePoint Server 2007 Training
http://www.microsoft.com/downloads/details.aspx?familyid=673DC932-626A-4E59-9DCA-16D685600A51&displaylang=en

Categories