We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem with Inserting HTML at bookmarks

I am using evaluation version of Aspose Words 6.1.0,
I am replacing the bookmarks in the templates with HTML content like this…

string DocItemTextHTML = "<body>" +
"<table border='1' align='center'>" +
"<tr align='center'>" +
"<td>No#</td>" +
"<td>Req.</td>" +
"<td>Description</td>" +
"<td>Results</td>" +
"<td>ActualResults</td>" +
"<td>Grade</td>" +
"<td>Date</td>" +
"</tr>" +
"<tr align='center'>" +
"<td>Number</td>" +
"<td>Name</td>" +
"<td>Test</td>" +
"<td>Criteria</td>" +
"<td>Test 1</td>" +
"<td>&nbsp;</td>" +
"<td>&nbsp;</td>" +
"</tr>" +
"</table>" +
"</body>";
Bookmark bookDocDocItemText = docDocItem.Range.Bookmarks["SpecItemText"];
bookDocDocItemText.Text = ""; //error getting here
builderDocItem.MoveToBookmark("SpecItemText");
builderDocItem.InsertHtml(DocItemTextHTML);
builderDocItem.EndBookmark("SpecItemText");

if the HTML content is like above, i am getting an err…
but when i am attaching <br> tag or <some text><br> after the body tag/before table tag in the above HTML, I am not getting any error, it working fine…
but my requirement is, i should not add any text or
tags after the body tag or before the table tag…
i am not able to find why the error is coming when the HTML starts like <body><table>...... and why the error is not coming when the HTML starts like <body>table description<br><table>.................</table></body>
Any sugestions would be appreciated…

Hi
Thanks for your request. Could you please clarify what kind of error do you get? Also, please attach your document for testing. I will try to reproduce the problem and provide you more information.
Best regards.

Hi Alexey,
Thanks for your response,
I written the code like,

string DocItemNameHTML = "<body><b>Document Item</b></body>";
string DocItemImage = Server.MapPath("./Images/Blue hills.jpg");
string DocItemTextHTML = "<body>" +                 // I am not written any thing b/w <body> tag and <table> tag
"<table border='1' align='center'>" +
"<tr align='center'>" +
"<td>Test#</td>" +
"<td>Req.</td>" +
"<td>TestDescription</td>" +
"<td>ExpectedResults</td>" +
"<td>ActualResults</td>" +
"<td>Pass/Fail</td>" +
"<td>Performed By / Date</td>" +
"</tr>" +
"<tr align='center'>" +
"<td>Qual Item Number</td>" +
"<td>Related Spec Item=Item Number and Name</td>" +
"<td>Test Description</td>" +
"<td>Acceptance Criteria</td>" +
"<td>Test Result</td>" +
"<td>&nbsp;</td>" +
"<td><img height='50' width='50' src='"+DocItemImage+"' /></td>" +
"</tr>" +
"</table>" +
"</body>";
 
Document docDocItem = new Document(@"D:\Test\templates\SpecItem.dot");
DocumentBuilder builderDocItem = new DocumentBuilder(docDocItem);
Bookmark bookDocDocItem = docDocItem.Range.Bookmarks["SpecItemName"];
bookDocDocItem.Text = "";
builderDocItem.MoveToBookmark("SpecItemName");
builderDocItem.InsertHtml(DocItemNameHTML);
builderDocItem.EndBookmark("SpecItemName");

Bookmark bookDocDocItemText = docDocItem.Range.Bookmarks["SpecItemText"];
bookDocDocItemText.Text = "";    //I am getting error here
builderDocItem.MoveToBookmark("SpecItemText");
builderDocItem.InsertHtml(DocItemTextHTML);
builderDocItem.EndBookmark("SpecItemText");
// addedsome code here

Now it’s not working… getting error like Object reference not found… Please found attachment for error screen shot
when i am writting HTML like

string DocItemTextHTML = "<body>Document Item Text<br>" +                 // added some text after <body> tag
"<table border='1' align='center'>" +
"<tr align='center'>" +
"<td>Test#</td>" +
"<td>Req.</td>" +
.................  // Same above HTML

now its working fine…
but my requirement is i should not add any text after <body> tag…
please suggest me solving this problem…

Hi
Thank you for additional information. I cannot reproduce the problem on my side. Could you please attach your document here for testing?
Best regards.