Hello,
I want to save one .DOCX document as HTML using "SaveAs" method. The document contains a lot of content controls (around 4001).
If I remove them all or some of them the document is saved to html properly. But if I try to save it as HTML with all controls then the code breaks.
I have used the next code (using Microsoft.Office.Interop.Word):
var document = this.Application.ActiveDocument;
var originalPath = document.FullName;
document.Save();
document.WebOptions.Encoding = Office.MsoEncoding.msoEncodingUTF8;
document.WebOptions.RelyOnVML = true;
document.SaveAs(System.IO.Path.GetTempPath() + "\\test.html", WdSaveFormat.wdFormatHTML);
document.SaveAs(originalPath, WdSaveFormat.wdFormatDocumentDefault);
And also the next code that is the same but using Microsoft.Office.Tools.Word :
var vstoDocument = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
// Keep original path
var originPath = vstoDocument.FullName;
// Save original
vstoDocument.Save();
// Save HTML
vstoDocument.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
vstoDocument.WebOptions.RelyOnVML = false;
vstoDocument.SaveAs(System.IO.Path.GetTempPath() + "\\test.html", WdSaveFormat.wdFormatHTML);
//Save again as docx to maintain the session as word document without closing the Add-In
vstoDocument.SaveAs(originPath, WdSaveFormat.wdFormatDocumentDefault);
In both cases, the red code throw an error:
System.Runtime.InteropServices.COMException
HResult=0x800A14CA
Mensaje = Memoria o espacio en disco insuficiente. Word no puede mostrar la fuente solicitada.
Origen = <No se puede evaluar el origen de la excepción>
Seguimiento de la pila:
<No se puede evaluar el seguimiento de la pila de excepciones>
Details:
I am using:
Microsoft® Word for Microsoft 365 MSO (version 2201 compilation16.0.14827.20158) of 64 bits.
Microsoft Visual Studio Community 2019 (Versión 16.8.5).
.NET Framework 4.8.
I have tryed to fix the problem:
Removing all files into the temp folder due the message of enough space of disk memory but I have 250 GB of free space.
Installing Hebrew regarding to fonts.
Changing all fonts of the document to arial font.
But any solution of the previous not resolve the problem.
The strange think is that the html seems to be created into the temp folder but as I see the error message I am not sure if the document has been saved properly because it is too long.
Someone could help me or explain why the quantities of Content control affect to the "saveAs" method?