0

I have this code:

// Writing a byte[] to temporary folder as a word file
File.WriteAllBytes(Path.Combine(Path.GetTempPath(), formLanguage.FileName), formLanguage.FormFile);

var app = new Microsoft.Office.Interop.Word.Application();
Document doc = app.Documents.Open(Path.Combine(Path.GetTempPath(), formLanguage.FileName));

// what my main goal is to count the pages
var pageCount = doc.ComputeStatistics(
   Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages);

formLanguage.NumberOfPages = pageCount;
object saveOption = WdSaveOptions.wdDoNotSaveChanges;
object originalFormat = WdOriginalFormat.wdOriginalDocumentFormat;
object routeDocument = false;

// here is where the debugger just doesn't continue.
doc.Close(saveOption, originalFormat, routeDocument);
app.Quit();

When doc.Close is called my C# desktop application, it is just stuck and takes forever. Does anyone know what my mistake is or is it even possible to close a word document like this?

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
  • 2
    Could you make Word visible on the desktop to see if there is anything blocking going on (like a messagebox)? – Emond Feb 21 '20 at 10:21
  • [take a look in this SO](https://stackoverflow.com/questions/15231923/how-to-not-save-documents-using-microsoft-office-interop-word) – Kuba Do Feb 21 '20 at 11:58

0 Answers0