VSTO component fail me when I try to save as html a word document with 4001 Content Controls.

francho.garcia 1 Reputation point


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.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  


            // 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:



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>


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?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,480 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Eugene Astafiev 891 Reputation points

    The error message clearly states that not enough memory for the operation:

    Insufficient memory or disk space. Word cannot display the requested font.

    I'd suggest decreasing the number of content controls in the document. Or just try a newly created word document with the same font and several content controls. Does it work correctly?

    Where and when do you run the code? Is it a server-side?