Using custom OpenDocuments control to open custom file types in SharePoint

Using custom OpenDocuments control to open custom file types in SharePoint

Rate This
  • Comments 19

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

Attachment: Malag.OpenDocuments.zip
  • 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.

  • Awesome! Thanks!

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

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

  • 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"/>

    to

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

    ?

    -Manpreet

  • 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!

  • 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_ROOT\Malag.Sharepoint.OpenDocuments]

    @="Malag.Sharepoint.OpenDocuments"

    [HKEY_CLASSES_ROOT\Malag.Sharepoint.OpenDocuments\CLSID]

    @="{C666BAE7-23D2-47BC-A283-CB90CD23FBBC}"

    [HKEY_CLASSES_ROOT\Malag.Sharepoint.OpenDocuments\CurVer]

    @="Malag.Sharepoint.OpenDocuments.1"

    [HKEY_CLASSES_ROOT\Malag.Sharepoint.OpenDocuments.1]

    @="Malag.Sharepoint.OpenDocuments"

    [HKEY_CLASSES_ROOT\Malag.Sharepoint.OpenDocuments.1\CLSID]

    @="{C666BAE7-23D2-47BC-A283-CB90CD23FBBC}"

  • 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?

  • 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?

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

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

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

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

  • 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)

  • 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?

Page 1 of 2 (19 items) 12
Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post