Using custom OpenDocuments control to open custom file types in SharePoint
A customer was having a number of PDF files uploaded into their SharePoint sites. They were using Adobe Acrobat to edit and create PDF files. What customer wanted was, to be able to edit the PDF files directly from SharePoint by getting "Edit with Adobe Acrobat" option in the ECB menu.
We edited the DOCICON.xml file located at <drive>\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\XML to add a new entry for PDF in the <ByExtension> section:
<Mapping Key="pdf" Value="pdf.gif" EditText="Adobe Acrobat" OpenControl="SharePoint.OpenDocuments"/>
After adding the above given entry and restarting the IIS, we got the entry in ECB menu to edit the PDF files but it was not opening the Adobe Acrobat product when clicked on it, but rather throwing a JavaScript error.
As customer also wanted some more control over how PDFs are being edited, we decided to go by the custom OpenDocuments control.
A custom OpenDocuments control was implemented using C# in an attempt to replicate the functionality provided by SharePoint.OpenDocuments control. But with time, it was created into a generic control, that try to find out the application associated with the given file extension, on the client machine and try to do a ShellExecute to open the file.
As the custom control is implemented as a COM control, you would need to register the control in the registry of the client machine. There are a couple of sample registry files in the attached zip archive, which can take care of registering and un-registering of the control. The sample registry files assume that the control is in the GAC of the client machine.
On the SharePoint end, you would need to change DOCICON.xml file to tell SharePoint to use your custom control when clicked on your custom extension, by changing the <ByExtension> section entry to:
<Mapping Key="pdf" Value="pdf.gif" EditText="Adobe Acrobat" OpenControl="Malag.OpenDocuments"/>
Notice that we have changed the “OpenControl” attribute of <Mapping> tag to point to our custom control.
The code for Malag.OpenDocuments control is attached. Hope this provides you with pointers to get you started on the path of created custom OpenDocuments control implementation.
Happy Coding…
Comments
Anonymous
September 18, 2010
Great work, Manpreet! However, I think that the OpenControl should be the following: <Mapping Key="pdf" Value="icpdf.gif" EditText="Adobe Acrobat" OpenControl="Malag.SharePoint.OpenDocuments"/> Thanks again.Anonymous
October 21, 2010
Awesome! Thanks!Anonymous
October 21, 2010
MSJ: Nice catch! yes it should be Malag.SharePoint.OpenDocumentsAnonymous
November 27, 2010
The icon works fine... The edit part didn't work for me (SP 2010). Instead I get "The document could not be opened for editing. A Microsoft SharePoint Foundation compatible application could not be found to edit the document".Anonymous
December 16, 2010
The comment has been removedAnonymous
August 11, 2011
Manpreet, how would I go about installing your code on my SharePoint 2010 installation? This is a bit of functionality that I would love to have on my sites, but I'm new enough that I've only coded a few custom web parts myself. Detailed start-to-finish instructions would be greatly appreciated! Great work, btw!Anonymous
September 05, 2011
To be able to have both New and Edit work, the registry entries need to be set so both the Malag.Sharepoint.OpenDocuments as well as Malag.Sharepoint.OpenDocuments.1 are registered. It appears that New invokes Malag.Sharepoint.OpenDocuments.1 directly, while Edit invokes Malag.Sharepoint.OpenDocuments: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOTMalag.Sharepoint.OpenDocuments] @="Malag.Sharepoint.OpenDocuments" [HKEY_CLASSES_ROOTMalag.Sharepoint.OpenDocumentsCLSID] @="{C666BAE7-23D2-47BC-A283-CB90CD23FBBC}" [HKEY_CLASSES_ROOTMalag.Sharepoint.OpenDocumentsCurVer] @="Malag.Sharepoint.OpenDocuments.1" [HKEY_CLASSES_ROOTMalag.Sharepoint.OpenDocuments.1] @="Malag.Sharepoint.OpenDocuments" [HKEY_CLASSES_ROOTMalag.Sharepoint.OpenDocuments.1CLSID] @="{C666BAE7-23D2-47BC-A283-CB90CD23FBBC}"Anonymous
October 17, 2011
I'm hoping you can help me. I am trying to implement something based on your article, yet I am finding that the edit Document link never appears in the context menu. I put the dll in the GAC and ran your sample registry script but it didnt seem to help. Can you help me identify why sharepoint 2007 doesn't recognize the entry in the DOCICON.XML?Anonymous
October 18, 2011
The comment has been removedAnonymous
October 19, 2011
Jon, the same instructions would work for SharePoint 2010 also. You just need to install the Assembly and make changes to the DOCICON.XML file and that should be it.Anonymous
October 19, 2011
Paulo Barthelmess, Thanks for the update. I did not experience this when I was developing this code. I will do another test to see if this is still the case and update the blog accordingly.Anonymous
October 19, 2011
The comment has been removedAnonymous
October 19, 2011
Koz, can you remove all the code and registry entries and just make a DOCICON.XML entry and see you are getting Edit in Adobe Acrobat option in ECB menu? If not, then please paste your Mapping element here and I can check if there is something wrong with it.Anonymous
October 19, 2011
By putting this in DOCICON Mapping, I get the edit link, but says there is no compatible service when clicked: <Mapping Key="pdf" Value="pdf16.gif" EditText="Adobe Acrobat" OpenControl="Malag.SharePoint.OpenDocuments"/> By putting this in the DOCICON Mapping, I dont get the edit link at all: <Mapping Key="pdf" Value="pdf16.gif" OpenControl=""Malag.SharePoint.OpenDocuments"/> By Putting this in DOCICON Mapping, I get the edit link and it works: <Mapping Key="pdf" Value="pdf16.gif" EditText="Adobe Acrobat" OpenControl="AdobeAcrobat.OpenDocuments"/> By Putting this in DOCICON Mapping, I get the edit link and it works: <Mapping Key="pdf" Value="pdf16.gif" OpenControl="AdobeAcrobat.OpenDocuments"/> All of this is with or without the assembly in the GAC and entries in the registry. (this is both Koz and Chris. Sorry for the double post, they didn't seem to be showing up when I posted a few days ago)Anonymous
October 20, 2011
Nikkoi, it looks like COM object is not registered properly. Let me check the registry script once again and get back to you... in mean time can you try cleaning up the registry keys from your system and using the registry script given by Paulo Barthelmess in the comments above?Anonymous
October 20, 2011
The comment has been removedAnonymous
October 20, 2011
Hi Nikkoi, Thanks for confirmation and good to hear that it works now!!Anonymous
October 18, 2012
Manpreet, I can get this working fine with the vbs test file etc, even made some changes to the source that work fine. Although in Sharepoint 2010 I still get the "Sharepoint Foundation" can't find an application to edit this document error, even though all the correct changes have been made to the DOCICON file. It appears there is a javascript file in: C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS1033 called OWS.js that detects active x objects etc. Any idea of the changes I'd have to make to this to make this project complete? Thanks DaveAnonymous
November 16, 2012
Hy Manpreet, i know this Thread is a little bit old. But the Problem with .pdf or any documentformat other than MS Office is still the same. I have tried your solution, but always ran into a file beeing save local on my hard drive and have to upload it manually into Sharepoint 2010 Foundation. I have tried anything back and forth with no luck. But than i came across this Article msdn.microsoft.com/.../cc264288(v=office.14).aspx Talking about using the fUseLocalCopy, and it made click. I changed the DOCICON.XML to <Mapping Key="pdf" Value="pdf.gif" OpenControl="SharePoint.OpenDocuments.3"/> and to open the listitem in the Clientapplication and that did the Trick. Now i can edit .pdf File (and i guess any other extension) within Sharepoint and save it right back into Sharepoint. btw. i do not use Adobe Acrobat. I only have add some Text and do Markups in PDFs, so i use NitroPdfReader. Its free and does exactly what i need. So thats the way ahah i like it ahah :-) (took me 3 Days to figure that out)