I use an Open Office API in my ASP .NET application for reading text content from *.doc files.
public static bool getTextV2(string siteURL, string[] search)
{
//Create a new ServiceManager Type object
Type tServiceManager = Type.GetTypeFromProgID("com.sun.star.ServiceManager", true);
//Create a new ServiceManager Com object using our
//ServiceManager type object
object oServiceManager = System.Activator.CreateInstance(tServiceManager);
//Create our Desktop Com object
object oDesktop = Invoke(oServiceManager, "createinstance",
BindingFlags.InvokeMethod,
"com.sun.star.frame.Desktop");
//Create an array for our load parameter
Object[] arg = new Object[4];
arg[0] = siteURL;
arg[1] = "_blank";
arg[2] = 0;
arg[3] = new Object[] { };
//Create our new blank document
object oComponent = Invoke(oDesktop,
"loadComponentFromUrl",
BindingFlags.InvokeMethod,
arg
);
//Create an empty array for the getText method
arg = new Object[0];
//Get our Text Com object
Object oText = Invoke(oComponent,
"getText",
BindingFlags.InvokeMethod,
arg
);
Object Text = Invoke(oText,
"getString",
BindingFlags.InvokeMethod,
arg
);
string content = Text.ToString();
content = content.ToLower();
bool flag = true;
foreach (string current in search)
{
if (!content.Contains(current)) flag = false;
}
arg = new Object[0];
Invoke(oComponent,
"dispose",
BindingFlags.InvokeMethod,
arg
);
return flag;
}
public static object Invoke(object obj, string method, BindingFlags binding, params object[] par)
{
return obj.GetType().InvokeMember(method, binding, null, obj, par);
}
But I have the following error:
Retrieving the COM class factory for component with CLSID {82154420-0FBF-11D4-8313-005004526AB4} failed due to the following error: 80080005.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {82154420-0FBF-11D4-8313-005004526AB4} failed due to the following error: 80080005.
Source Error:
Line 56: //Create a new ServiceManager Com object using our Line 57: //ServiceManager type object Line 58: object oServiceManager = System.Activator.CreateInstance(tServiceManager); Line 59: //Create our Desktop Com object Line 60: object oDesktop = Invoke(oServiceManager, "createinstance",
So, there is a error at line 58.
Any ideas?