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

Free Support Forum - aspose.com

Convert Word Doc to HTML- but send to string variable instead of to Disk

Hello,
I’m new to Aspose and would like to know if there is a method that sends a document converted to HTML into a string variable instead of to Disk. I hava an editor control in a .NET 2.0 C# environment, and I’d like the users to be able to browse for a .Doc or .Docx file, have it converted to HTML and then have the newly converted HTML version displayed in the editor, instead of saving it to disk. Once reviewed and/or modified, the user can save it to a database.
Any help would be appreciated. Here’s the code snippet – I’m sure it’s wrong since I’m getting junk in the editor:

LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Html;
Document doc = new Document(strFilePath, loadOptions);
edtNewContent.Content = doc.ToTxt();

THANKS,

Hi
Thanks for your inquiry. You can use code like the following to convert document to HTML string:

public string ConvertDocumentToHtml(Document doc)
{
    string html = string.Empty;
    // Save docuemnt to MemoryStream in Hml format
    using (MemoryStream htmlStream = new MemoryStream())
    {
        doc.Save(htmlStream, SaveFormat.Html);
        // Get Html string
        html = Encoding.UTF8.GetString(htmlStream.GetBuffer(), 0, (int)htmlStream.Length);
    }
    // There could be BOM at the beggining of the string.
    // We should remove it from the string.
    while (html[0] != '<')
        html = html.Substring(1);
    return html;
}

Hope this helps.
Best regards,

Yes, that works perfectly . Thank you!