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… Smile

Comments (19)
  1. MJS says:

    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.

  2. UG says:

    Awesome! Thanks!

  3. MSJ: Nice catch! yes it should be Malag.SharePoint.OpenDocuments

  4. Half says:

    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".

  5. Half Sun, I have not tested this in SP2010 and would not be able to comment on its behavior. Once I am able to test it with SP2010, will update the post with any changes if required.

    BTW, did you change the mapping line from:

    <Mapping Key="pdf" Value="pdf.gif"  EditText="Adobe Acrobat" OpenControl="Malag.OpenDocuments"/>


    <Mapping Key="pdf" Value="pdf.gif"  EditText="Adobe Acrobat" OpenControl="Malag.SharePoint.OpenDocuments"/>



  6. Jon says:

    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!

  7. Paulo Barthelmess says:

    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











  8. Koz says:

    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?

  9. Chris K says:

    I have tried following what you did in this article, but I cant get Sharepoint to recognize that I have a custom com object.  The VBScript fires it flawlessly, but when I add the setting into the DOCICON.XML, I lose the "Edit Document" option in Sharepoint and cant edit the document.  Is there something special to do to get sharepoint to recognize it?

  10. 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.

  11. 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.

  12. Hi Chris, this is nothing special that need to be done. The COM object specified will be invoked by the script, regardless if it is a custom COM component or SharePoint's.

    You can remove all the code and just make an entry into DOCICON.XML file to check if you are still loosing the Edit Document option in SharePoint?

    Also, please try the updated Registry script provided by Paulo Barthelmess in the comment above and see if this applies to your scenario. If yes, then I would update the file attached to the blog accordingly.

  13. 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.

  14. 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)

  15. 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?

  16. I'm not sure what I broke, but I decided to start over today.  I used the above change to the Registry, and I added my sample code to what you provided and it worked out of the box. I wish the edit option on the popup worked, but this is a good start.   I feel embarrassed, but Thank you very much for your help.  Today I just made a huge leap forward.

  17. Hi Nikkoi,

    Thanks for confirmation and good to hear  that it works now!!

  18. 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?



  19. 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…/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)

Comments are closed.

Skip to main content