Thursday, March 17, 2011

SharePoint Tip: Did you know that…..in SharePoint Content types?

When creating SharePoint site columns and adding them to content types programmatically, we normally commit out changes by calling the update function in the syntax:-

ContentType.Update(); 

Did you know that on the site content type you are updating, this function does not tick ‘Yes’ on the “Update all content types inheriting from this type?” but leaves it tick as ‘No’ as seen below, did you know? I didn’t.

image

So now for this option to be tick ‘Yes’, you would have to call the same function, but this time pass the boolean as follows:-

ContentType.Update(true);

Please take note that I would have already declared ‘ContentType’ as SPContentType of course.

Happy coding!

Tuesday, March 8, 2011

SharePoint: How to create a custom action to open Word Documents using "Edit in Microsoft Word".

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!