Please note: This blog is no longer active. My new blog is located at http://blog.timwheeler.io

Wednesday, October 21, 2009

SharePoint Helper Code Library (SPHelper)

I have added my SharePoint Helper library to my new SharePoint Code Zone.

This is a collection of utility classes in C#.  A lot of the code is mine, but I also want to credit Edvar Pereira (Edge), Michael Van Den Berg,  Andrew Cox from Readify, Chris Johnson from Microsoft (I think Chris might have written some of the MSDN based code) and possibly other smart people I have worked with.  If anyone out there see's their code let me know and I'll credit.

PowerShell Execution Policy

So I decided it was high time I looked into PowerShell and see what all the fuss was about.  Grabbed a script I needed from CodePlex.  Installed PowerShell.  Found the syntax to run the script:  .\myScript.ps1

Great, so I execute it.  And nothing.  It just shows a new line with a flashing cursor.  Did it run? Did it error?  Nothing.  Hmm.. So I work out I can add a line to tell me the script is running:

Write-Host "Begin"

Cool, so I try again.  Nothing, nada, zip.  No error, no msg.  My script definitely isn't running or I should have seen begin.

One of my colleagues, (Thanks Pete), points out that it could be the execution policy.  I think sure, sounds plausible, but shouldn't there be an error message telling me that the policy won't allow scripts?  You would think so but in this case, NO!

So, I ran:

get-executionpolicy

it returned: Restricted.

"Restricted" is the default policy on any powershell install (Or maybe its OS related, I am on Win 2003).

So I ran:

set-executionpolicy unrestricted

and voila, I could now run my script.

But I'm mad I tell you... MAD!!!!

For more info about this see: http://207.46.16.252/en-us/magazine/2007.09.powershell.aspx

Tuesday, October 20, 2009

Keywords not showing in Office 2003 integration

Noticed today that the Keywords field from the content type doesn't appear in the Word integration to SharePoint 2007 SP2.  Didn't investigate why as we are giving up on improving the Office 03 integration.  Waiting for the enterprise to catch up to Office 07 or maybe skip and go straight to 2010....

Monday, October 19, 2009

SharePoint 2007, Rich Text fields and Office 2003

I had an interesting issue to deal with today. 

Issue (with SharePoint 2007 Service Pack 2):

When using Word 2003 and saving a new document to a document library in SharePoint, a validation issue exists where it ignores input of data in a required field and continually prompts the user to enter data into that field.

This occurs when the field is using Rich Text, is required and the user is saving from Word 2003 (Likely other Office 2003 products have the same issue but I have not tested this).

Steps to reproduce

1

Create a document in Word 2003, add some content.

2

Attempt to close the document, and save to a document library with a required Rich Text field.  Enter data into the Rich Text field.

3

Click OK and a validation error occurs stating "You must specify a non-blank value for [FIELD]"

Cause:

Word accesses the SharePoint server and displays a small window allowing the user to enter data for the metadata fields.  It references some html and javascript on the SharePoint server which handles saving and validation.  The javascript file (BFORM.js) doesn't save the state of the Rich Text control, and subsequent validation calls fail.

Resolution Options:

1.       Upgrade to Office 2007

2.       Don’t use Rich Text fields in the metadata schemas (Content Types)

3.       Manually fix the Javascript file (Not best practice and my invalidate your warranty - but hey, what good is that anyway)

4.       Raise the issue to Microsoft Support (and wait 2 months)

Javascript Fix Option

If you choose to fix the javascript here is what you need to do:

Locate the file at:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033

*Note: The folder 1033 may be different depending on your language.

Edit this file and do the following:

1.  Add a global variable "var custom_ActiveForm;" some where towards the top of the file.

2.  Search for the function "function OWSForm" and

add the following line to the top of that function:

custom_ActiveFormName = stName;

//Customisation to fix issue with Word 2003

3. Search for the function "function RTE_SaveSelection" and add the following to the end of this function:

try
    {
        document.forms[custom_ActiveFormName][strBaseElementID].innerText = docEditor.activeElement.innerHTML;
    } catch (e) { }

 

What this does:

It makes the Html Editor save the data into the appropriate form property. 

*Please note:  I generally don't recommend this option as I cannot be sure it doesn't impact any other areas of SharePoint.  Use at your own risk.