This project has moved. For the latest updates, please go here.

insert picture in word fail

Oct 30, 2012 at 2:42 PM

Hi,

I'm trying include a picture in word body. After run rotine, the document do not open.

it is showing a message: cannot be opened because there are problems with the contents. Then is offered a option to correct the problem. If I accept the problem is corrected and the picture is included ok.

Can you help me?

Nov 8, 2012 at 11:10 AM

How are you saving the document when you've edited it using DocX? Are you streaming it to the client or opening it up via file explorer? Some coding would assist here.

Nov 8, 2012 at 2:25 PM

Hi mattmoleman,

thank you for your reply.

I'm saving by code. See:

      Try
            Dim wordDoc As DocX = DocX.Load(document)
            Dim docImage As Novacode.Image = wordDoc.AddImage(image)
            Dim docPicture As Novacode.Picture = docImage.CreatePicture()
            docPicture.Height = 60
            docPicture.Width = 150
            Dim countReplace = count
            Dim indexx As Integer = 0
            Try

                For Each paragraph As Novacode.Paragraph In wordDoc.Paragraphs
                    Dim f = paragraph.FindAll(value)
                    If f.Count > 0 Then
                        paragraph.RemoveText(indexx, value.Length)

                        paragraph.InsertText("    ")
                        paragraph.InsertPicture(docPicture, 0)
                    End If
                Next
                wordDoc.Save()

            Catch ex As Exception

            End Try



I'm using the default routine, found here.

Regards,

Nov 9, 2012 at 5:20 PM

That should be fine if you were to open the word document via file explorer. - Do you dispose of the document (wordDoc.dispose) after you have finished with it? I say this because it may still be locked in the save state when you attempt to open the file.

 

I've not had any problems with inserting images, saving and then opening the document, but I am pretty new to DocX myself.

Do you get these errors without the inserting of the picture?

Nov 18, 2012 at 12:15 PM

Hi Mattmoleman,

Sorry about delay.

Yes, I open the document in windows explorer, after program end.

The error occurs when I open the document in windows explorer.

From: Mattmoleman [email removed]
Sent: sexta-feira, 9 de novembro de 2012 14:21
To: vladimir@ttes.com.br
Subject: Re: insert picture in word fail [DocX:401245]

From: Mattmoleman

That should be fine if you were to open the word document via file explorer. - Do you dispose of the document (wordDoc.dispose) after you have finished with it? I say this because it may still be locked in the save state when you attempt to open the file.

I've not had any problems with inserting images, saving and then opening the document, but I am pretty new to DocX myself.

Do you get these errors without the inserting of the picture?