1

Working with Office 2010, I'm able to access to .docx file without problem, using DocumentFormat.OpenXml.

But, for .doc, it fails (the files have old winword format).

Microsoft.Office.Interop.Word.Application wordApp;
wordApp = new Microsoft.Office.Interop.Word.Application();
Object oFileName = fullFilePath;
object missing = System.Reflection.Missing.Value;
object oFormat = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatDocument97;
object saveChange = false;
try {
    Microsoft.Office.Interop.Word.Document doc = 
        _wordApp.Documents.Open( ref oFileName, ref missing , ref missing ,
            ref missing , ref  missing , ref missing , ref missing ,
            ref missing , ref missing , ref oFormat, ref missing ,
            ref isVisible, ref missing , ref missing , ref missing , ref missing );

    textBuilder.Append( doc.Content.Text );

    wordApp.Documents.Close( ref saveChange, ref missing, ref missing );
    }
catch (Exception ex) {
    textBuilder.Append( "<ERROR>" + "\n" + ex.Message );
    }
finally {
    wordApp.Quit(ref saveChange, ref missing, ref missing );
    wordApp = null;
    }

With all possibles values of 'WdOpenFormat', I got always exception (fictive "concurent access").

How to solve that ?

Best regards.

  • I don't write it in my sample, but I use parameter ReadOnly=true too. But it doesn't work. The problem is only for .doc files. I only need to extract the content of the file in text for text search. – francois.piondrancy Jul 10 '14 at 12:53
  • A wonderfull answer.... I develop application in C++ since 25 years 12 hours/day as ingeneer in industry companies, and I don't need that 'somebody writes code for me'. I only need professional answer. You can send me your c# project, I will run it on my computer and shows you that It doesn't work everywhere. Best regards. – francois.piondrancy Jul 10 '14 at 13:05
  • So, I copy your code and...I can't execute it because function Open() is not compliant with prototype: namespace Microsoft.Office.Interop.Word { [Guid( "0002096C-0000-0000-C000-000000000046" )] [DispId( 19 )] Document Open ( ref object FileName, ref object ConfirmConversions, ref object ReadOnly, ref object AddToRecentFiles, ref object PasswordDocument, ref object PasswordTemplate, ref object Revert, ref object WritePasswordDocument, ref object WritePasswordTemplate, ref object Format, ref object Encoding, ref object Visible, ... Best regards. – francois.piondrancy Jul 10 '14 at 13:23
  • Ok, I have the solution. Before trying to open the file, I had open an DSOFile.OleDocumentPropertiesClass object to access to file properties, without freeing it. And this lock the .doc access (and not .docx files). – francois.piondrancy Jul 10 '14 at 14:41

0 Answers0