| Author: Bhushan Poojary 13 Oct 2008 | Member Level: Silver | Rating: Points: 6 |
using Microsoft.Office.Interop.Word...Source(http://nishantrana.wordpress.com/2008/07/17/opening-and-inserting-a-picture-in-word-document-programmatically-using-c/)
Put the following code in the button click event handler
// For optional parameters create a missing object object missing = System.Reflection.Missing.Value; // Create an object for filename, which is the file to be opened object fileName=@”C:\MySecond.doc”; // Create an object of application class ApplicationClass WordApp = new ApplicationClass(); // open the document specified in the fileName variable Document adoc = WordApp.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); // We can insert the picture using Range objects AddPicture method // To insert a picture at a particular location in the word document // insert a table over there and then refer that location through range object Range rngPic = adoc.Tables[1].Range; // we can even select a particular cell in the table //Range rngPic = rng.Tables[1].Cell(2, 3).Range; rngPic.InlineShapes.AddPicture(@”C:\anne_hathaway.jpg”, ref missing, ref missing, ref missing); WordApp.Visible = true; [\CODE]
|