Newcomer Help

I am probably doing something really stupid, but I cannot get my code to work!!! I have an asp.net website which collects information into a database. At the end of the process I want to write the database fields to bookmarked positions in a word document. I had it working perfectly in Word, but of course that doesnt work when you publish the site.

I have the following code, just to test writing to the document before I pull out the database values. It brings up the correct document, but has not filled in the word “test” to the bookmark. Any ideas what I am doing wrong, and any tips on the best way to do this would be appreciated.

Dim NewDoc As New Aspose.Word.Document("C:\Inetpub\wwwroot\ImportsSite\STCCert.DOC")
Dim builder As New Aspose.Word.DocumentBuilder(NewDoc)
builder.MoveToBookmark("txtAuthNo", True, False)
builder.Write("test")
DocName = Right(NewAppNo, 5) & ".doc"
NewDoc.Save(DocName, Aspose.Word.SaveFormat.FormatDocument, Aspose.Word.SaveType.OpenInBrowser, Response)

Hi,

Thank you for your interest in Aspose.Word.

Your code looks correct, please attach your document to let us reproduce the issue. However, performing mail merge operation is more applicable than using bookmarks when one needs to populate a document template with data from a data source. To know more, please refer to the Performing Mail Merge section of the Aspose.Word Programmers Guide located here:
https://docs.aspose.com/words/net/

Thanks for your prompt response. I cannot get the mailmege to work either, even if I pass in strings rather than database tables. This is the ammended code:

Dim NewDoc As New Aspose.Word.Document("C:\Inetpub\wwwroot\ImportsSite\STCCert.DOC")
' Create an array of the field names 
Dim fieldNames() As String = {"Authno", "vetname"}
' Create an array of the field values
Dim fieldValues() As Object = {"1234", "Mr Vet"}
'Fill the fields in the document with user data.
NewDoc.MailMerge.Execute(fieldNames, fieldValues)
'Save the document
DocName = Right(NewAppNo, 5) & ".doc"
NewDoc.Save(DocName, Aspose.Word.SaveFormat.FormatDocument, Aspose.Word.SaveType.OpenInBrowser, Response)

(Basically copied from your help!!!)

I attach the document I am using. The first two fields are word mergefields named “AuthNo” and “Vetname”, the rest are bookmarks I was trying to use previously - I will change all fields to be consistant once I have this working for a couple of fields.

Again the document is displayed, but the fields do not show the values passed in.

Thanks once again for your help

Shellie

The point is that merge field names are case sensitive. Ensure that the names you use in your code (or those retrieved from the data source) exactly fit the names you use in the template. In your test code, use names “AuthNo”, “VetName” and everything will work.

That worked brilliantly, thanks for the help.

Shellie