开发者

Office 2003: Unable to find Microsoft.Office.Interop.Powerpoint dll

I have created a windows appli开发者_C百科cation which makes use of Office.dll and PowerPoint dlls of Microsoft office 2003. At design time, when I am adding reference to these dlls to my project it refers following path:

C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.PowerPoint\

The application runs perfect on the machine where it is developed, but when I am trying to run it on other machine it fails. The exception it is throwing is:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException

I tried to locate the above path on my test machine, but I am surprised that, though office 2003 and 2007 is installed (2 different machines), this folder is not present over there.

Can anybody help me resolving this issue?


1.There is an Office 2003 Primary Interop Assemblies (PIA) redistributable is a Microsoft Windows Installer package that contains the Primary Interop Assemblies for Microsoft Office 2003 products you can get it from here it includes an assembly you need

2.You can set true to the "Copy Local" key for this assembly in your project references properties, in this case it would be copied into the output folder of your project

3.You don't really need it to work with MS Office applications, though it makes it easier. Below is an example of how you can open a presentation without interop classes

Type officeType = Type.GetTypeFromProgID("PowerPoint.Application");
object officeInstance = Activator.CreateInstance(officeType);
// set visible
object value = -1;
officeType.InvokeMember("Visible", BindingFlags.SetProperty, null, officeInstance, new object[] { value });
// open presenation
object objTrue = -1;
object objFalse = 0;
object fileNameObj = presentation_file_name;
object documents = officeType.InvokeMember("Presentations", BindingFlags.GetProperty, null, officeInstance, null);
documents.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, documents, new object[] { fileNameObj, objTrue, objFalse, objTrue });

didn't test this exact one, but smth like this works fine for me, regards


The interop dll you are looking for is installled on your deevelopment machine in the GAC. As such it is not a part of the standard deployment. You need to copy it over by hand.

Another option (and may be a cleaner one) would be to run the Office installation on the target machine and let it install all what's necessary. Just make sure that you selected proper options

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜