External Link for Editing a SharePoint Document 

Tags:

Have a need to edit a document that is stored within SharePoint, but provide the link within another application?

Using just the URL to the document will only give you read-only access to the document, but a little bit of digging on the javascript involved provides a fairly simple solution.

Note that this has only been tested with Word 2007 and Excel 2007.

The short answer is to reference the following scripts (I do this in the <HEAD> section of the page):

<script type="text/javascript" language="javascript" src="http://<sharepoint server>/_layouts/1033/init.js"></script>

<script type="text/javascript" language="javascript" src="http://<sharepoint server>/_layouts/1033/core.js" defer></script>

For example:

<script type="text/javascript" language="javascript" src="http://tw-lt-m90-001/_layouts/1033/init.js"></script>

<script type="text/javascript" language="javascript" src="http://tw-lt-m90-001/_layouts/1033/core.js" defer></script>

Then have the following for the link:

<A onfocus="OnLink(this)" HREF="<document url>" onclick="return DispEx(this,event,'TRUE','FALSE','TRUE','','0','SharePoint.OpenDocuments','','','','21','0','0','0x7fffffffffffffff')">

 <document name>

</A>

For example:

<A onfocus="OnLink(this)" HREF="http://tw-lt-m90-001/Documents/Hello%20World.doc" onclick="return DispEx(this,event,'TRUE','FALSE','TRUE','','0','SharePoint.OpenDocuments','','','','21','0','0','0x7fffffffffffffff')">

Hello World

</A>

Here is a full example that includes the icon for the file type as well.

<HTML>

 

<HEAD>

<title>Documents</title>

<script type="text/javascript" language="javascript" src="http://tw-lt-m90-001/_layouts/1033/init.js"></script>

<script type="text/javascript" language="javascript" src="http://tw-lt-m90-001/_layouts/1033/core.js" defer></script>

</HEAD>

 

<BODY>

  

<TABLE width="100%" cellspacing=0 cellpadding=0 border=0>

<TR>

<TD>

<A TABINDEX=-1 HREF="http://tw-lt-m90-001/Documents/Hello%20World.doc" onclick="return DispEx(this,event,'TRUE','FALSE','TRUE','','0','SharePoint.OpenDocuments','','','','21','0','0','0x7fffffffffffffff')">

<IMG BORDER=0 ALT="Hello World.doc" title="Hello World.doc" SRC="http://tw-lt-m90-001/_layouts/images/icdoc.gif">

</A>

</TD>

<TD>

 <A onfocus="OnLink(this)" HREF="http://tw-lt-m90-001/Documents/Hello%20World.doc" onclick="return DispEx(this,event,'TRUE','FALSE','TRUE','','0','SharePoint.OpenDocuments','','','','21','0','0','0x7fffffffffffffff')">

Hello World

 </A>

</TD>

</TR>

</TABLE>

 

</BODY>

</HTML>

To reference an icon it is simply "ic<ext>.gif" (http://<sharepoint url>/_layouts/images/ic<ext>.gif, e.g., http://tw-lt-m90-001/_layouts/images/icdoc.gif).  For a full listing of icon files see all "ic*.gif" files in the TEMPLATE\IMAGES directory under the 12 hive.

 
Posted by Kirk Liemohn on 14-Oct-07
10 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Links to this post

Comments


Philip commented on Monday, 17-Mar-2008
I think you can use the VSTO (Visual Studio Tools for Office) to do that, but than you'll have to implement the code for each type of office document and each version of office. Using the existing scripts of SharePoint is very usefull but its difficult to find documentation about those javascript functions. It seams people who find that solution just enquire on which javascript code is executed when we open a document. So, if you have more information, it would be great from you to share it again :) Thank you.


Jason commented on Friday, 18-Apr-2008
Great post - I was playing with that JS for a while and couldn't get it to work. I am wondering if you also came up with a way to link directly to the document library's delete prompt as well?


Kirk Liemohn commented on Sunday, 20-Apr-2008
Jason, I haven't tried doing a delete this way, but you should be able to view the browser's HTML source to figure it out.


Lennin commented on Friday, 25-Apr-2008
That didn't work for me whenever I have 2003 clients. I used this instead: Memo.doc


Lennin commented on Friday, 25-Apr-2008
Oops the code didn't show before: <a href="#" onclick="editDocumentWithProgID2('/myWeb/Lists/Documents/Memo.doc', '', 'SharePoint.OpenDocuments', '0', 'server/myWeb', '0')"> Memo.doc </a>


nq316 commented on Saturday, 1-Nov-2008

inwowgold commented on Monday, 8-Dec-2008

car wash commented on Monday, 29-Dec-2008

car wash commented on Monday, 29-Dec-2008
Pursestock supplier provides the best Gucci replica,Chanel replica,Louis Vuitton replica; show you every detail of photos of replica handbags. Do you think it is hard to believe that we have such a high-quality wholesale replica handbags,Hermes birkinand Hermes kelly? Let me tell you, when you have our Gucci replica purses, you will understand why Chinese manufacturing industry and replicas products are so well-developed. The authentic Gucci replica, you can buy for collections. But the genuine high prices are outrageous, how many collections you can buy with such a high price,if you like Monogram Canvas,speedy 30,chanel 2.55 bag ? Jadeshow’s replica Tiffany Jewelry and Replica Bvlgari Jewelery looks just like the real thing. Why pay more for a single piece of Tiffany Replica jewelry,Bvlgari Replica Jewelry when you can treat yourself to a number of replica pieces for the same price or less? Be simply spectacular with contemporary Tiffany-inspired jewelry!Jadwshow delights in the opportunity to offer our customers fine Tiffany Bracelets, Tiffany Necklaces, Tiffany Earrings, Tiffany Rings, Tiffany Bangles,Gucci jewelry replica, all at remarkably low prices.

Name:
URL:
Email:
Comments:

CAPTCHA Image Validation