If you’re following Ty’s Office 365 Newswires and read this article about Microsoft already having sold five million Office 365 seats in roughly two and a half months, I’m sure you would agree with me that Office 365 is set to change, if not revolutionize the way people use and interact with Microsoft Office.

Of course this opens a whole world of possibilities to developers and even more so for the few, the proud Office developers. I love to dream up ways to integrate Microsoft Office with different applications and online services and in today’s post I’ll show you how to write a Microsoft Outlook Add-in that will save an e-mail’s attachments and/or the entire e-mail to an Office 365 hosted SharePoint Online list.

This add-in will only be available in Microsoft Outlook so make sure it is the only selected application in the list of supported applications.

After completing the wizard, add a new ADXBackstageView component to the AddinModule designer surface and also add two ADXBackstageFastCommandButton controls. Set the following properties for the first button

Name: adxButtonSaveAttachments

Caption: Save Attachments to SharePoint Online

InsertAfterIdMso : FileSaveAs

Ribbons: OutlookMailRead

And set the following for the second button:

Name: adxButtonSaveEmail

Caption: Save E-mail to SharePoint Online

InsertBeforeIdMso : SaveAttachments

Ribbons: OutlookMailRead

With all the properties set, your design should resemble the following image:

When I first started with this article, I had the intention of uploading the files using the SharePoint Foundation 2010 Managed Client Object Model. Unfortunately, after numerous attempts and some further research I found it was just not as simple as the examples on that page indicated it should be. The problem is that when you need to access the SharePoint object from outside Office 365 or outside the browser, you need to use active authentication.

I’m not going to go into much detail about this, but I recommend you read Wictor Wilen’s article on this topic. I also based this example on the solution he suggested.

Ok, with that out of the way, let’s add the MSOnlineClaimsHelper.cs and WcfClientContracts.cs classes that Wictor wrote about (you can download the files from the article mentioned earlier, it is also available in this article’s sample project).

Next, we’ll add our own SharePointHelper.cs class. The code listing for this class is as follows:

Save the class and switch back to the AddinModule designer and select the BackstageView component we’ve added earlier. Select the “Save Attachments to SharePoint Online” button and add an event handler for its OnClick event. Add the following code to the event handler:

This code essentially does the same as the previous listing, except that instead of only saving the e-mail’s attachments it will save the entire e-mail to the SharePoint library.

Build, register and run your project and open an e-mail in Outlook that has attachments.

When you click on the File Menu you should see the two buttons we’ve added earlier:

Click on the “Save Attachment to SharePoint Online” button. It should take a few seconds and when you view the Shared Documents library in SharePoint you should see all the files that was attached to the e-mail.

Finally, click on the “Save E-mail to SharePoint Online” button. The entire e-mail should now be saved in the Shared Documents library.

41 Comments

Hi there,I just bought Add-in Express for Office and .NET, and i have a small question relating this example, what happens after you press the “Save E-mail to SharePoint Online” button, do you get a total tree of Folders you can upload to, or does everything Need to be prespecified

Hi Petrus,
Welcome aboard!
When saving the email to SharePoint you wont be prompted to choose the save location. In this example it will be saved to the Shared Documents library in SharePoint. The code that does the work is :

Hi Pieter, Thanks alot for your reply,
I have currently been put upon the Task of creating such an Addin that allows users to save emails on SharePoint over a button click (which is found on the Toolbar), only that i also have to Show them the Basic SharePoint Tree of Folders that they can choose from.
My question (I’m a Young beginner, i hope the question isn’t stupid):
Could i make such a Thing possible on the example Code through small modifications? – (Do I Need to configure a Webservice ?)
Thanks in Advance, I’m looking Forward to your Answer.

Check the article carefully. The adxButtonSaveAttachments button’s InsertAfterIdMso property should be FileSaveAs and the adxButtonSaveEmailInsert button’s BeforeIdMso property should be SaveAttachments

I’m deeply sorry for having invoked a missunderstanding.
I’m already using the sample, I bought Add-in Express, and then loaded the Project, had a Little Trouble with the SharePoint references, since i don’t have it installed on my Windows 8, and I’m trying to use it for Office365,which i later fixed after downloading the “SharePoint Foundation 2010 Client Object Model Redistributable”.
I rebuild my Project and press the Debugg button, Outlook starts, and i select an email(which has an attachment) and then go to File, but don’t see the two buttons

Hi Pieter,
I tried both of them now,
out of despair i restarted reading the articel carefully again,
and i see that besides Building and Debugging you also say Register.
Quote “Build, register and run your Project”, how do you Register?,
maybe it’s that why i can’t see them

I have one more question regarding the issue,
to be quite correct i’m actually looking for some tips which i might gather from a more experienced Person, such as you.
I’m using your sample, which is working quite well, though I Need to connect to an Office 365 through ADFS(only E-Mail required),
which if basically done over the browser, takes you from the Standard Office 365 Login page(after giving in the E-Mail) and Redirects you to a new page where it asks you to enter the Username,
do you have any ideas on how to go for this Thing in the sample:
-Insert E-Mail
-Let the addin wait for the Redirection
and then give in Credentials(Username) which (after that) would take me to the page (i think this happens automatically) which i requested in the first place.
Always greatefull for your help!

Hi there Pieter,
I am currently trying to modify the Code so i can use the it’s capabilities on an ADXRibbon Tab (Group – Button),
but i’m also suffering from terrible problems while i’m trying to do that.
I’ve set up the button (that is supposed to save a *selected e-mail to SharePoint)visualy and everything, but when I’m in the code and I’m Trying to copy everything you did for the “mailReadBackstageView” i get into some issues in the beginning, ex:

//|under Initialize Component| i try to add the following:
this.SaveButton.OnClick += new AddinExpress.MSO.ADXRibbonOnClick_EventHandler(this.SaveButton_OnClick);

after that i copy your whole method and change the name but it gives me an Error back saying:
“An implicit conversion from type ‘AddinExpress.MSO.ADXRibbonOnClick_EventHandler’ in ‘AddinExpress.MSO.ADXRibbonOnAction_EventHandler’ is not possible.”
What can i Do? I try to ask this in the Forum but it seems i can’t post a new thread.
thanks for your Help

Mmm…when you generate the event handler for the button’s click event, did you select it in the designer and double-click next to the OnClick event in the properties window?
This will generate the event handler code for you.

Hi Pieter,
Just did what you said,
i debugged, and while having an email selected in outlook i pressed my Ribbon button.
Visual Studio threw me directly at this part of the Method (which i have simply copied from yours)

“if (currInspector.CurrentItem is Outlook.MailItem)”
could this be because in your example you have to open an email in the email Inspector window (if yes, please give me some guidance), if not, what could it be

You will receive an error if you do not have an e-mail open. The sample was done with a button on the ribbon of an open email’s window(Inspector).
However, you can have a button on the main Outlook window(Explorer), the user then needs to select an e-mail and click the button.

Anil again.. I tried you code in vs2013 for Outlook 2013 and it deployed fine. However, I could not see the options for saving email to SharePoint and saving attachments to share point site. Any ideas..

To be honest, I have not worked with SP2007, so unfortunately I would not be able to tell you how to accomplish the same with the SP 2007 api.
I suggest having a look at the SharePoint 2007 SDK documentation. The Outlook bit of adding buttons and saving attachments will remain the same.

This technology is now available for our custom development services only. Based on the Add-in Express for Office core, it is designed for building custom-tailored Office add-ins with far less coding than you usually have to do. Plus, it includes all Add-in Express features such as True RAD, visual designers, Outlook view and form regions, etc.

Get the best platform for building version-neutral, fast and easy deployable plug-ins by using Add-in Express projects templates, visual designers, components and wizards in combination with a perfect Delphi compiler.

This is an extension for Visual Studio that allows developers to quickly create WiX-based setup projects in a familiar Visual Studio way.

The Designer for WiX Toolset lets you forget the plain Windows Installer XML and concentrate on your deployment logic. It integrates several editors with the Visual Studio IDE and provides a set of vdproj designers to configure the file system, registry, user interface, custom actions, launch conditions and more for your setup projects.

The innovative technology for customizing Outlook views and forms. It is included in all Add-in Express for Office products and can be used to extend Outlook views, e-mail, task and appointment windows, To-Do bar, Reading and Navigation panes with your own custom sub-panes.

Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in
the United States and/or other countries. All other trademarks are property of their respective owners.