Office Developer Blog
The definitive blog for finding the latest news and code tricks for Office developers.
 

July, 2011

  • Office Developer Blog

    Running Sample Outlook Add-in's

    • 0 Comments

    A few customers have asked about how to run the time-reporting add-in that was published on MSDN as Creating a Simple Time-Reporting Tool Based on the Outlook 2010 Calendar, and discussed in the blog post Time-Reporting Tool now Available as an Outlook Add-in!

    In general, because the main reason for us to provide code samples is to demonstrate programming techniques that use our object models, we typically provide only the source code for add-ins. For those of you interested in further customizing the add-ins, you are welcome to do so by downloading the source code, and using Microsoft Visual Studio to modify the code for your specific purposes.

    For those of you who have Microsoft Visual Studio 2010 and would like to run a sample add-in, you can start the add-in from Visual Studio by following this process:

    1. Download the source code from the indicated site. For example, for the time-reporting add-in, you can download the source files from Outlook 2010: Time-Reporting Tool Based on the Outlook 2010 Calendar.
    2. Unzip the set of source files, and double-click the solution file (.sln) of the add-in. This opens the solution in Visual Studio.
    3. In Visual Studio, build the solution by clicking Build and then Build Solution. The build action should succeed.
    4. Close Outlook if it is opened.
    5. Start the add-in by clicking Debug and then Start without Debugging. This opens Outlook and starts the add-in.

    As an example, to run the time-reporting add-in, you would need to have Microsoft Outlook 2010 installed. After running the above procedure in Visual Studio, Outlook opens and you should see the Add-Ins tab on the explorer ribbon in Outlook. Click the Add-Ins tab, and you can proceed to use the add-in as described in the article “Creating a Simple Time-Reporting Tool Based on the Outlook 2010 Calendar”.

    For those of you who do not have Visual Studio 2010 but would like to try the time-reporting add-in, I have attached an installation package in a zip file to this blog post for your convenience.

    Note: The time-reporting add-in was developed to illustrate programming techniques and is not intended to be a commercial product. The installation package was created using Visual Studio 2010 and the same add-in source code that is available for download. The package is provided for convenience, and has not been code-signed. After you run Setup in step 3 of the process below, you will see a dialog box that says “Publisher cannot be verified. Are you sure you want to install this customization.” Click Install if you want to proceed to try running the add-in.

    Follow these steps to use the attached installation package to install and run the time-reporting add-in:

    1. Close Outlook.
    2. Save a copy of the attached zip file for the installation package on your local drive.
    3. Unzip the installation package.
    4. Double-click the Setup.exe file to install the add-in.
    5. Open Outlook.
    6. You should see the Add-Ins tab on the explorer ribbon in Outlook. Click the Add-Ins tab, and you can proceed to use the add-in.

    If you are interested in creating your own installation package, you can see Deploying Office Solutions for more information.

  • Office Developer Blog

    Attaching a File or an Outlook Item to an Outlook Message

    • 0 Comments

    Attaching a file to a Microsoft Outlook mail item is one of the most popular customer actions in Outlook.

     

    Naturally, many power users also ask how to do this programmatically. The Outlook object model provides the Attachment object, Attachments.Add method, and an Attachments property for each of the Outlook item objects (for example, mail, appointment, contact, meeting, and task items), to support adding an attachment to an Outlook item. You can attach a copy of a file, an Outlook item like a message or contact, or an Object Linking and Embedding (OLE) object to an Outlook item. In particular, if you are attaching a file to a mail item that uses Rich Text Format (RTF), you can also specify the location to place the attachment in the body of the mail message, and the display name of the attachment.

    Ken Getz, a Microsoft MVP and an expert in a multitude of technologies including Microsoft Office, Microsoft Visual Studio, Visual Basic, and C#, recently contributed a set of four code samples to illustrate a few tasks around attachments.

    • How to: Attach a File to an Outlook Email Message illustrates the basic attachment task of programmatically attaching one or more files to an outgoing email message in Outlook. In order to send a mail message from a given SMTP email address, you also need to identify the corresponding Outlook account. This topic also shows the secondary tasks of finding the corresponding Account object given the SMTP address of the sender, creating the mail message, setting the recipients, subject, and body properties of the mail message, and finally sending the message that contains the attachments.
    • How to: Attach an Outlook Contact Item to an Email Message shows another basic attachment task of attaching an Outlook contact item to an outgoing mail message. This topic includes a secondary task of creating a contact item before attaching it and sending it along with the mail message.
    • How to: Limit the Size of an Attachment to an Outlook Email Message shows a practical task of how to programmatically check the total size of attachment files before actually sending a mail message. The topic shows a custom event handler for the Application.ItemSend event. The custom event handler uses the Size property of each attachment to sum up the total size of all attachments, compares the total size with the size limit, and cancels the send event if the total size exceeds the limit.
    • How to: Modify an Attachment of an Outlook Email Message is a slightly more advanced topic that shows how to use the MAPI property PidTagAttachDataBinary and the PropertyAccessor object to programmatically modify an attachment file before sending it along with the mail message. This technique is useful if, for example, you want to systematically convert text file attachments to upper case, before actually sending the mail message. This topic also makes use of the Application.ItemSend event.

    The sample code in these topics is presented in both C# and Visual Basic. Hope you can adapt the code to suit your scenarios.

Page 1 of 1 (2 items)