Free Support Forum - aspose.com

Some bookmarks not being replaced

I wonder if someone can help me with this rather thorny issue.


We distribute a .NET program that uses Aspose.Words to create Word docs from a database. I’ve inherited the code, so don’t necessarily have a full understanding of how it works, but I know that it’s replacing bookmarks in the document with data from DB fields. This may not be the best way (I have seen that there’s mail merge functionality available) but it’s how I inherited the project, and I need to stick with it for the time being.

This works fine on every machine I have come across - except for one client, who has 4 or 5 machines that all have the same problem - some of the bookmarks get replaced, and others don’t.

I have checked that the template they are using is identical (copied from my dev machine) and that their version of Aspose Words is the same (7.0.0.0). They are using Word 2007, which I have on my dev machine, and are running Win XP Pro SP3. They are replacing data from the same db fields into the same bookmarks in the same template (sample attached).

I know that any errors Aspose throws are usually displayed, because we already had to wrestle with the “grand parent node should be the same” problem experienced elsewhere, so I don’t think a full-on error is causing the problem. Are there any scenarios in which Aspose Words will silently fail?

Any help appreciated,

Al

Hi

Thanks for your request. I used the following code for testing and I am unable to reproduce the problem:

// Open template.

Document doc = new Document(@"Test001\BLANKCR.doc");

// Loop through all bookmarks and replace thir values.

foreach (Bookmark bookmark in doc.Range.Bookmarks)

bookmark.Text = bookmark.Name + " Replaced";

// Save output.

doc.Save(@"Test001\out.doc");

I used the latest version of Aspose.Words for testing. You can download it from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Answering your question, Aspose.Words can silently resolve errors in the document, but this document seem to look fine and it works as expected on my side. Could you please try running the code I mentioned above for testing and let me know if it works as expected? Maybe the reason of the problem is data you put into the bookmarks.

Best regards,

Thanks for your reply, Alexey.


It is going to be tricky to test that code because I would have to build another application and deploy to the client’s network: as per my post, the existing code runs fine and throws no errors when run anywhere else. I will go down that route if every other line of enquiry closes.

I would like to pick up on the question of the data going into the bookmarks: if Aspose Words failed to set the bookmark text, would it throw an exception?

Lastly, you mention the latest version of Aspose.Words - I was informed by the last developer when I was passed the project that my licence “only covered version 7” - is that possible, or do I have the right to download the latest version 10.2?

Kind regards,

Al

Hi

Thanks for your request. Yes, Aspose.Words should throw an exception. But it would be better if you get the data that causes the problem and attach them here for testing.

You can download the latest versions of Aspose.Words and test it in evaluation mode. Or request a temporary license and test without evaluation version limitations.

http://www.aspose.com/corporate/purchase/faqs/temporary-license.aspx

Best regards,

OK, so I got to the bottom of the problem, and as you may have guessed, the problem was not with the Aspose library. An incorrect DML retrieval had deleted some of the mail merge field entries.


Thanks for looking into this with me in any case.

Al

Hi

It is perfect, that you already found the solution. If you need more assistance, we will be glad to help you.

Best regards,