SIGN UP MEMBER LOGIN:    
ARTICLE

Insert Picture with hyperlink in word file using C#

Posted by Hiren Soni Articles | Visual C# August 24, 2010
Here you can learn how to add picture with hyperlink in word file using C#.
Reader Level:

HTML clipboard

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

Output:

1.gif

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.
 

Login to add your contents and source code to this article
share this article :
post comment
 

thanks for share. but i don't understand with the project, what do i can?

Posted by snake vietnam May 22, 2011

send me please project! nvien@mail.ru thanks!!!

Posted by nguyen vien le Feb 06, 2011
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor