This project has moved and is read-only. For the latest updates, please go here.

Bug AddImage

Sep 18, 2009 at 4:53 PM
Edited Sep 18, 2009 at 4:55 PM

Hi! :)

hope you are fine!

I'm traying to use your InvoiceExample project, but a exception is throw when I try to open a image resource

"Object reference not set to an instance of an object"

I've my resource folder and my images, the code line is:

Novacode.Image logo = document.AddImage(g_assembly.GetManifestResourceStream("Novacode.Resources.Blue_hills.jpg"));

could you help me to find the mistake! :$


thank so much!


Sep 18, 2009 at 7:22 PM
Edited Sep 18, 2009 at 7:32 PM

Hello danielosh,

once you have added your image to the project, you need to right click it and select properties

On the properties window, set the build action to Embedded Resource

You then need to find out what the embedded resources full name is, the best way to do this is with the below code.
Assembly g_assembly = Assembly.GetExecutingAssembly();
string[] resource_names = g_assembly.GetManifestResourceNames();
If you debug this code and hover your mouse over the variable resource_names, you can examine its contents.

In the above image you can see that my images full name is ConsoleApplication9.Untitled.png, this is the name I would use in the following code
Image logo = document.AddImage(g_assembly.GetManifestResourceStream("ConsoleApplication9.Untitled.png"));

Let me know if this helps you.
kind regards and happy coding,
Cathal Coffey
Sep 23, 2009 at 6:43 PM

hi Cathal!!!

I just want to tell you that I already done what you say and the proyect was builded successfullllllllllyyyyyyyyyyyy!!!

thank you very much! you are great!

Now, i've an other q'stion :$
what i want to do is design and implement a kind of "Templete editor".. what is it¿
there was aby way to do an aplication where the user will define his owner templates ? where he can put label's, comboBox, etc and then save it and when a user run the aplication he can fill only the datas allowed by the user that made the template?
something like the IDE of VS or CS.. where you can put labels and all kind of controls....

well.. see you soon!!!

and thaks again!

Sep 23, 2009 at 9:43 PM
Hi Danielosh,

no problem at all, I am glad that I could help.

Oct 13, 2009 at 4:26 PM

hi  Cathal!

i've a q'stion!

how can I add textBox, CheckBox, radioButton, comboBox, listBox, etc in my .docx using DocX?


Oct 13, 2009 at 8:52 PM
Hi danielosh,

DocX does not yet support high level containers such as textBox, CheckBox, radioButton, comboBox, listBox. DocX is actually quite a young library, I still have lots of lower level features to add before I start supporting higher level containers.

I am sorry to be the bearer of bad news.
kind regards,
Oct 14, 2009 at 3:02 PM
Edited Oct 14, 2009 at 3:21 PM

Hi again Cathal!

I'm very excited playing with DocX... but... i've an other q'stion :$
lines before you explain me how is possible to add an image in a .docx with DocX... but.. there's a way that user select which image he want? I try as follow:

Imagen is a class with private members and public properties

DocX _document;
Imagen _imagen = new Imagen();

private void btn_BuscaImagen_Click(object sender, RoutedEventArgs e)
  if(ds_OFD.ShowDialog() != false)
    ds_OFD.Title ="Seleccione una imagen";
    ds_OFD.Filter = "archivos *.bmp, *.jpg, *.png | *.bmp; *.jpg; *.png";
    _imagen.Ds_nombre = ds_OFD.SafeFileName;
    _imagen.Ds_ruta = ds_OFD.FileName;

//Sobrecarga para imagen
private DocX CreaTemplate(Imagen _img)
       _document = DocX.Load(@"Template.docx"); //Si ya existe el documento, lo lee y escribe sobre el
    _document = DocX.Create(@"Template.docx"); //Si no existe, lo crea
  Novacode.Table layout_tabla = _document.InsertTable(3/*Columnas*/, 1/*filas*/);
  layout_tabla.Design = TableDesign.TableNormal;

  Novacode.Paragraph Parrafo_izq_sup = layout_tabla.Rows[0].Cells[0].Paragraph;
  Novacode.Image _ImagenI = _document.AddImage(g_assembly.GetManifestResourceStream(_img.Ds_ruta));
  Picture _imagenPicture = Parrafo_izq_sup.InsertPicture(_ImagenI.Id);
  return _document;


could you help me please! :'(

Oct 14, 2009 at 7:25 PM


i'm s0 embarrassed ab0ut my q'sti0n in my last p0st! :$ :$ :$
i d0n't kn0w why i didn't see that _document.AddImage accept a string fileName argument!!! :S



Oct 14, 2009 at 10:02 PM
Hi Danielosh,

Sorry for my late reply. I just got home now and read your posts. Have you found a solution to your problem?

kind regards,