How to replace with html comment

I’m attempting to save a Word document as HTML. Prior to saving, I run a doc.range.replace to replace certain items in the document. One thing I’m trying to do is add an HTML comment, such as:

<!-- some_comment -->

So that in the HTML output, it retains this correctly as an HTML comment. However, it seems to be converting it to the following:

&lt;!-- some_comment --&gt;

How do I force it not to convert to the above and just save exactly what I originally replaced with?

I tried the example at https://reference.aspose.com/words/net/aspose.words/documentbuilder/inserthtml/

but it just removes the original text without replacing with the html comment that I put in InsertHtml, such as:

build.InsertHtml("<!-- comment -->")

It does not exist in the final output for some reason.

Hi

Thanks for your inquiry. There is no way to insert HTML comments in the document. If you need to have comments in the output HTML, you can insert them after converting document to HTML.
Best regards,

Ok, that should be doable. Out of curiosity, do you ever plan on offering this as a feature? Seems like it could be useful for people to place comments in the html with the DocumentBuilder.

Hi

Thanks for your inquiry. I think this feature is out of scope of Aspose.Words. Aspose.Words is designed to work with MS Word documents. Even if you insert HTML into document, it is converted to Aspose.Words DOM:
https://docs.aspose.com/words/net/aspose-words-document-object-model/
Best regards,

I’m using the following to save the document as html into a stream. How can I modify the resulting html that is in the stream? I don’t want to first save to a file:

ms = New MemoryStream doc.Save(ms, SaveFormat.Html)

How can I modify ms as text?

Hi there,
Thanks for your inquiry.
Try using the code below:

// Save document to stream in HTML format.
MemoryStream stream = new MemoryStream();
doc.Save(stream, SaveFormat.Html);
stream.Seek(0, SeekOrigin.Begin);
// Read the HTML document into a string.
StreamReader reader = new StreamReader(stream);
string testString = reader.ReadToEnd();
reader.Close();
// Insert comment.
testString = testString.Insert(testString.IndexOf(""), "");
// Save the modified HTML document to a new stream.
MemoryStream newStream = new MemoryStream();
StreamWriter writer = new StreamWriter(newStream);
writer.Write(testString);
writer.Close();

Thanks,