Opening SharePoint documents for Edit from Client Applications
The ActiveX component “SharePoint.OpenDocuments” is used to open SharePoint documents ready for editing. It is documented here and is usually called from JScript code in a web page. But what about if you want to open a SharePoint document from a client application, such as a .NET WinForm or WPF application?
You might try the following code using the full URL to the document:
System.Diagnostics.Process.Start(docUrl);
This will open the document in the client application (e.g. Microsoft Word), but it will always be opened read-only.
The following code will create an version specific instance of SharePoint.OpenDocuments and then call the EditDocument method to open the document:
public static void OpenDocumentForEdit(string docUrl)
{
Type t = null;
// get the correct version specific version...
t = Type.GetTypeFromProgID("SharePoint.OpenDocuments.1");
if (t == null)
t = Type.GetTypeFromProgID("SharePoint.OpenDocuments.2");
if (t == null)
t = Type.GetTypeFromProgID("SharePoint.OpenDocuments.3");
if (t == null)
{
System.Diagnostics.Process.Start(docUrl); // best we can do, will open read-only
return;
}
Object o = Activator.CreateInstance(t);
object[] openParms = { docUrl, string.Empty };
t.InvokeMember("EditDocument",
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance,
null, o, openParms);
}
Note that different versions of Office install different versions, and this code attempts to open the version installed on the client application. If none could be found it opens the document, albeit in read-only mode. When the method is called the following dialog will be presented to the user:

Great post Nick for client applications. After lot of search on the web, finally I got here.
Still I am unable to use your code as error at Object o = Activator.CreateInstance(t) prevents me to move on.
Error is ” {System.Runtime.InteropServices.COMException (0×80040154): Retrieving the COM class factory for component with CLSID {9203C2CB-1DC1-482D-967E-597AFF270F0D} failed due to the following error: 80040154.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
I see in Registry that “SharePoint.OpenDocuments.3″ & “SharePoint.OpenDocuments.4″ have the same data {9203C2CB-1DC1-482D-967E-597AFF270F0D}
Kalyan
July 5, 2012 at 7:27 pm
I got the answer compiling the code in x86 rather than Any CPU (or) x64 solved the problem.
Kalyan
July 5, 2012 at 7:48 pm
Kalyan, Glad you found a solution and thanks for posting your question. Regards, Nick.
Nick Grattan
July 6, 2012 at 6:49 am
Authentication Issue
Nick,
I am trying to override the default system windows credentials(Kalyan) in my Client Ojbect Model using ‘TestLogin’ and tried executing your activator.createinstance method for editing office documents using client applications.
Both the logins do exist on SharePoint portals with
Kalyan -> Full Control
TestLogin -> visitor permission
But the document opens up using the credentials of Kalyan rather than TestLogin.
Question: How can a document be opened using TestLogin rather than the default windows login (Kalyan)?
Kalyan
July 11, 2012 at 1:17 pm
I guess you will need to impersonate the “TestLogin” user, have a look at WindowsImpersonationContext: http://msdn.microsoft.com/en-us/library/system.security.principal.windowsimpersonationcontext.aspx. I have not tried this, but I think it’s the solution for you. Regards, Nick.
Nick Grattan
July 12, 2012 at 7:06 am