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,

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

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!