Imagine you have a SharePoint custom search webpart, and on your search results, you return word documents, you will obviously want to at times be able to open them in your MS Word client program for editing.
So basically, depending on your office client installed on your local machine, there are 2 different approaches that can be made for Office 2003 and Office 2007/10, using the same function "editDocumentWithProgID2".
For Office 2003:
- If your document libraries versioning settings have got "Require Check out" ticked, then you will first want to check out the document using:
onclick="CheckoutviaXmlhttp(‘{SiteURL}’, ‘{DocumentDownloadURL}’)"
- Then to open the document, you use:
onclick="return editDocumentWithProgID2(‘{DocumentDownloadURL}’, ”, ‘SharePoint.OpenDocuments’, ’1′,’{SiteURL}’, ’0′);" href="#"
- and now combining the above 2 actions into one clickable action:
onclick="CheckoutviaXmlhttp(‘{SiteURL}’, ‘{DocumentDownloadURL}’); return editDocumentWithProgID2(‘{DocumentDownloadURL}’, ”, ‘SharePoint.OpenDocuments’, ’1′,’{SiteURL}’, ’0′);" href="#"
For Office 2007/10:
- Again if your document libraries versioning settings have got "Require Check out" ticked, this line will do it all, i.e. check out and open the document:
onclick="editDocumentWithProgID2('{DocumentDownloadUrl}', '', 'SharePoint.OpenDocuments', '1', '{SiteUrl}', '0')" href="#"
- Note that the variable "1" means that the document is being opened in Edit mode. If you change it to 0, the document would open in read-only mode.
Happy Coding!
So basically, depending on your office client installed on your local machine, there are 2 different approaches that can be made for Office 2003 and Office 2007/10, using the same function "editDocumentWithProgID2".
For Office 2003:
- If your document libraries versioning settings have got "Require Check out" ticked, then you will first want to check out the document using:
onclick="CheckoutviaXmlhttp(‘{SiteURL}’, ‘{DocumentDownloadURL}’)"
- Then to open the document, you use:
onclick="return editDocumentWithProgID2(‘{DocumentDownloadURL}’, ”, ‘SharePoint.OpenDocuments’, ’1′,’{SiteURL}’, ’0′);" href="#"
- and now combining the above 2 actions into one clickable action:
onclick="CheckoutviaXmlhttp(‘{SiteURL}’, ‘{DocumentDownloadURL}’); return editDocumentWithProgID2(‘{DocumentDownloadURL}’, ”, ‘SharePoint.OpenDocuments’, ’1′,’{SiteURL}’, ’0′);" href="#"
For Office 2007/10:
- Again if your document libraries versioning settings have got "Require Check out" ticked, this line will do it all, i.e. check out and open the document:
onclick="editDocumentWithProgID2('{DocumentDownloadUrl}', '', 'SharePoint.OpenDocuments', '1', '{SiteUrl}', '0')" href="#"
- Note that the variable "1" means that the document is being opened in Edit mode. If you change it to 0, the document would open in read-only mode.
Happy Coding!
Comments
I will check back for any response. Thank you, this would be great if I could use it.
My application is not on the same server as SharePoint at my site.