I'm generating word doc on the fly by using html in asp .net with C#. And I want to add image at top but after creation of word doc I'm not able to see that image. I don't want to use Word or any third party dll.
Please Help me out

Below is code snippet :

strinv = "<html>" +

               "<body>" +
 "<div><img src=" + "SnH.JPG" + "alt=" + "Spencer N Hills" +/> </div><br/>" +
               "<p style=" + "background-color:Silver; border-width:medium; border-style:ridge; border-color:Gray;" + ">" + firstname + middlename + lastname + "</p><br />" +
               "<p> Position:" + designation + "</p><br />" +


 "<p>" + experience + "</p><br />" +
               "</body>" +


        string textfilename = firstname.Trim() + "_" + middlename.Trim() + "_" + lastname.Trim() + "_" + "SnH.doc";
        System.IO.StreamWriter owrite;
        owrite = System.IO.File.CreateText(Server.MapPath("~/Resume/Temp/") + textfilename);

Recommended Answers

>Problem in adding image in word doc in C#

You need to use Word Object Model.

Take a look at thread - http://social.msdn.microsoft.com/forums/en-US/vsto/thread/5d68fa72-3fd2-49ca-bf4b-dce4c2899839/

Jump to Post

All 4 Replies

My hosting provider is not supporting Microsoft word library or Interop word or any other dll. So Please help for same way to code.(generate doc on the fly)

I used following c# code to insert image to word document.

WordDocument document = new WordDocument();
WordDocumentBuilder builder = new WordDocumentBuilder(document);
builder.CharacterState.FontSize = 24;

//Add floating image using builder
using (Stream stream = File.OpenRead("sample.jpg"))
    FloatingImage floatingImage1 = builder.InsertFloatingImage(stream, "jpg");
    floatingImage1.Wrapping.WrappingType = ShapeWrappingType.Square;

you can download the library in here

By virtue of the fact that you are using HTML, have you tried embedding a base64 version of the image in the img tag?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.