0
votes

How to add Word Document/Excel Document file to custom folders created inside outlook using VSTO addin C#

2

2 Answers

0
votes

Outlook Object Model would not let you explicitly create a document object - you can start with adding a regular MailItem object using MAPIFolder.Items.Add, add the attachment, then set the MessageClass properly appropriately (look at an existing document item with OutlookSpy - click Item or IMessage button), and save the message.

If using Redemption is an option, you can use its RDODocumentItem object - you can either call RDODocumentItem.SetDocument method or call RDOFolder.Items.Add and specify the full path to an existing file - see http://www.dimastr.com/redemption/rdodocumentitem.htm for more details.

0
votes

Outlook.DocumentItem objDocItem = ParentFolder.Items.Add("IPM.Document");

            //objDocItem = ParentFolder.Items.Add("IPM.Document");

            Outlook.Attachment objAtt = objDocItem.Attachments.Add(strFilePath);
            objDocItem.Subject = objAtt.FileName;


            string strFileType = Path.GetExtension(strFilePath);
            switch (strFileType)
            {
                case ".doc":
                case ".docx":
                    objDocItem.MessageClass = "IPM.Document.Word.Document.8"; break;
                case ".xls":
                case ".xlsx":
                    objDocItem.MessageClass = "IPM.Document.Excel.Sheet.8"; break;
                case ".pps":
                case ".ppt":
                case ".pptx":
                    objDocItem.MessageClass = "IPM.Document.PowerPoint.Show.8"; break;
            }


            objDocItem.Save();