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
Related Q & A:
- How to replace a string inside of a Word Document?Best solution by Stack Overflow
- How do I attach a word document to an email?Best solution by Yahoo! Answers
- How to recover corrupted word document?Best solution by techrepublic.com
- How to put a picture into a yahoo email?Best solution by Yahoo! Answers
- How to put a picture in the body of email message?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.