# Region traditional reading Method
Object readonly = true;
Object missing = system. reflection. Missing. value;
Object filename = file. fullname;
Microsoft. Office. InterOP. Word. applicationclass wordapp = new applicationclass ();
// Open the specified file (the number of COM parameters varies in different versions. In general, all except the first one will use missing)
Microsoft. Office. InterOP. Word. Document Doc = wordapp. Documents. Open (ref filename, ref missing, ref readonly, ref missing,
Ref missing, ref missing,
Ref missing, ref missing,
Ref missing, ref missing );
// Obtain the text in the DOC file
String text = Doc. content. text;
// Close the file
Doc. Close (ref missing, ref missing, ref missing );
// Close com
Wordapp. Quit (ref missing, ref missing, ref missing );
# Endregion
// The word is referenced statically in the program. If it is not installed, an error is returned. A program such as this requires that the corresponding version of the program be installed.
// You can use dynamic references to check whether a program is installed or whether the version is compatible.
# Region reflection read
Type objwordtype = type. gettypefromprogid ("Microsoft. Office. InterOP. Word ");
Object objwordapp = activator. createinstance (objwordtype );
Object objdocuments = objwordapp. GetType (). invokemember ("documents", bindingflags. getproperty, null, objwordapp, null );
Object [] openparas = {file. fullname };
Object OpenDocument = objdocuments. GetType (). invokemember ("open", bindingflags. invokemethod, null, objdocuments, openparas );
Object opencontent = OpenDocument. GetType (). invokemember ("content", bindingflags. getproperty, null, opendocument, null );
Object openttext = opencontent. GetType (). invokemember ("text", bindingflags. getproperty, null, opencontent, null );
// Set whether the interface is displayed. The read information is not displayed.
// Object [] pars = {true };
// ObjWordApp. GetType (). InvokeMember ("Visible", BindingFlags. SetProperty, null, objWordApp, pars );
# Endregion
Return opentText. ToString ();