views:

185

answers:

2

I have the below code that I harvested from MSDN. There intent there seems to have been as an Add In and as such I am having a problem with the this.Application.CreateItem(...) portion. What do I need to do differently to do this from my winform app?

private void AddAttachment(){

Outlook.MailItem mail =this.Application.CreateItem(Outlook.OlItemType.olMailItem)as Outlook.MailItem;

mail.Subject = "An attachment for you!";

OpenFileDialog attachment = new OpenFileDialog();

attachment.Title = "Select a file to send";
attachment.ShowDialog();

if (attachment.FileName.Length > 0)
{
    mail.Attachments.Add(
        attachment.FileName,
        Outlook.OlAttachmentType.olByValue,
        1,
        attachment.FileName);
    mail.Recipients.Add("Armando Pinto ");
    ((Outlook._MailItem)mail).Send();
}
A: 

Make sure you're in a VSTO project so you get the Office References loaded. If it's complaining up there, it's probably because it doesn't know what object you're trying to create.

Brandon
+1  A: 

I found the solution here, kinda. It doesn't really answer my question but it does work.

http://www.codeproject.com/KB/IP/SendFileToNET.aspx

Refracted Paladin
Hey This was really helpfull, Sorry I have run out of votes today, will vote this when I remember. Cheers
zonkflut