How to put a word document onto an email?

How to Put a Word Document on the Body of an Email in C#

  • Answer:

    Knowing how to insert the contents of a Microsoft Office Word document to the body of an email can save you time sending emails. Word is a processing program included in the Microsoft Office suite. Microsoft Outlook is a mail management system also included in Office. C Sharp, also known as C#, is an object-oriented computer programming language used to develop computer applications. If you need to send the contents of a Word document through email you can automate the process by applying a few simple steps. Difficulty: Moderate Instructions Open Microsoft Visual C# Express and select "New Project..." on the left pane of your screen. Double-click "Console Application." Click the "Project" menu, select "References" then click the "COM" tab. Select "Microsoft Word <version number> Object Library" and "Microsoft Outlook <version number> Object Library." Click "OK." Press "Ctrl," "A" and "Delete" to remove existing code. Copy and paste the following code to your "Program.cs" module. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Word; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { String WordText = ""; Application wrdApplication = new Application(); object missing = System.Reflection.Missing.Value; Document wordDoc = wrdApplication.Documents.Open(@"G:\WordDoc.doc", ReadOnly: false, Visible: false); wordDoc.Activate(); wordDoc.ActiveWindow.Selection.WholeStory(); WordText = wordDoc.ActiveWindow.Selection.Text; Microsoft.Office.Interop.Outlook._Application olkApplication = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook._MailItem olkMailItem = (Microsoft.Office.Interop.Outlook._MailItem) olkApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); olkMailItem.Display(false ); olkMailItem.To = "[email protected]"; olkMailItem.Subject = "Adding a word document"; olkMailItem.Body = WordText; olkMailItem.Display(true); olkMailItem.Send(); wordDoc.Close(false, missing, missing); } } } Edit the following line of code and type the path for your Word document. Document wordDoc = wrdApplication.Documents.Open(@"C:\WordDoc.doc", ReadOnly: false, Visible: false); Press "F5" to run your program.

Jaime Avelar at eHow old Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.