Hi,

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>" +

               "</html>";

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

Hi,
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 meeting, networking, learning, and sharing knowledge.