.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Insert Picture with hyperlink in word file using c#

Posted By:Hiren Soni       Posted Date: August 23, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

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

Code and explanation:

 

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


Hope you understand it.

 

Thank you.



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend