none
Errors when working with Office.Interop.Outlook, not sure how to fix RRS feed

  • Question

  • I'm getting two errors with the code listed below that don't make sense to me.

    This is the first time I'm working with the Office.Interop, so I know I'm slipping somewhere.

    Error 1: The best overloaded method for 'Microsoft.Office.Interop.Outlook._Application.CreateItemFrom Template(string,object)' has some invalid arguments.

    Error 2: Cannot convert from 'byte[]' to 'string'.
    I don't see where it thinks I'm declaring a Byte, any help is appreciated.

    I've also already declared Using Outlook = Microsoft.Office.Interop.Outlook

    private void button1_Click(object sender, EventArgs e)
            {
                Outlook.Application app = new Outlook.Application();
                Outlook.MailItem mail = app.CreateItemFromTemplate(Properties.Resources.Untitled) as Outlook.MailItem;
                mail.Subject = "I'm testing";
                mail.Save();
            }

    Wednesday, October 24, 2012 2:58 PM

Answers

All replies

  • CreateItemFromTemplate takes a string with the fully qualied file name. You cannot pass a binary resource - you need to save it to a temporary file first.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!


    Wednesday, October 24, 2012 4:43 PM
  • So, than I should save the OFT resource file that is in the project to say the System Temp Directory.

    After that, I would call the file to execute the rest of the code and create the email.

    Monday, October 29, 2012 6:28 PM
  • That is correct.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Monday, October 29, 2012 6:33 PM
  • Wish you were my instructor on Office Development. Much easier to understand they way you explain it.
    Monday, October 29, 2012 7:38 PM