Insert Picture with hyperlink in word file using C#


Insert Picture with hyperlink in word file using C#

Here you can learn how to add picture with hyperlink in word file using C#.


// first we are creating application of word.
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();

// now creating new document.
WordApp.Documents.Add();

// see word file behind your program

WordApp.Visible = true;

// get the reference of active document
Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;

// get the range
Microsoft.Office.Interop.Word.Range drange = doc.Range();

// now add the picture in active document reference and store the reference of picture in inlineshape object
Microsoft.Office.Interop.Word.InlineShape picture = drange.InlineShapes.AddPicture("c:\\logo.gif", Type.Missing, Type.Missing, Type.Missing);

// noew add the hyperlink to object of inlineshape
drange.Hyperlinks.Add(picture, "http:\\www.c-sharpcorner.com", Type.Missing, Type.Missing, Type.Missing, Type.Missing);

// file is saved.
doc.SaveAs("c:\\hello.doc", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
// application is now quit.
WordApp.Quit(Type.Missing, Type.Missing, Type.Missing);



Reference: http://www.c-sharpcorner.com/UploadFile/hrojasara/2902/


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: