'How to add .docx file to custom folder in outlook using addin c#

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



Solution 1:[1]

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();

Solution 2:[2]

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 (I am its author) 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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chiku sharma
Solution 2