If you would like to discuss anything, please contact me via email: Howard.Bayliss@sequence.co.uk

Friday, October 28, 2011

SharePoint Anonymous Access

I was trying to change the Anonymous Access settings for a list, as per this screen:


SharePoint Anonymous Access checkboxes

However, when I checked the "Add Items" box and clicked OK, it did not save the changes. Everytime I repeated this and went back to the screen, the "Add Items" box was not checked.


The cause of the problem was that the Anonymous Policy for the SharePoint Application (that hosted the site) had been changed. By default this is set to "None". However, it had been set to "Deny Write".


SharePoint Anonymous Policy

There wasn't a good reason for this and switching it back to "None" fixed the problem.

Thursday, October 27, 2011

DataFormWebPart maximum field lengths

I used a DataFormWebPart to generate a custom edit form. Our client wanted to limit the maximum length of various fields on this form, but didn't want these to be applied site-wide.

The built-in SharePoint fields (FormField, TextField, NoteField, etc) don't have a "maxlength" property.

The solution was to modify the template for the various fields within the DataFormWebPart XSLT, to include RegularExpressionValidators.

Credit to Bart McDonough for this. His blog post relates to creating a new field type, but I tried it within the DataFormWebPart and it worked.

The nice thing about this is that the validation will take place on both the client and the server

Here is a sample from my DataFormWebPart XSLT file. This sets the maximum length of a text field to 80 characters.

Note that the curly braces in the regular expression have to be escaped. If you don't do this, the XSLT will break.



<SharePoint:TextField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="Title" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}">

<Template>

<asp:TextBox id="TextField" runat="server"/>
<asp:RegularExpressionValidator
ControlToValidate="TextField"
ValidationExpression=".{{0,80}}"
Text="Value cannot exceed 80 characters."
runat="server" />

</Template>

</SharePoint:TextField>

Wednesday, October 26, 2011

SharePoint Check "page layout"

In code, I had a reference to an SPFile object and I wanted to check if the SPFile was a page layout file.

I used code (similar to the sample below) to do this. It checks to see if the file's parent list is the master page / page layout library.

Maybe you know a better way?


string url = " -- ABSOLUTE PATH TO YOUR FILE -- ";

using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
SPList masterPagelist = site.GetCatalog(SPListTemplateType.MasterPageCatalog);
SPFile file = web.GetFile(url);

if (file.Item.ParentList.ID == masterPagelist.ID)
{
// The file is in the master page library.
}
}
}

Monday, October 24, 2011

SharePoint SummaryLinks "Edit Properties"

While logged-in as a user with Contributor permissions, I noticed that the toolbar for a Summary Links field was not visible on the Edit Form of a publishing page.

This is is shown in the picture below:

SummaryLinks has no

I suspect this is a SharePoint bug as the toolbar was visible when the page was in WYSIWYG edit mode.

Also, the issue did not occur when logged-in as a Site Collection administrator.

A work-around to this issue is to give the user the Manage Lists permission. However, this is really not something you should consider lightly as it gives editors an awful lot of power.

I'm going to speak to Microsoft to see what they say about it and then I'll post an update....

UPDATE


Microsoft has acknowledged that this is an "Offbug" (as they call it). In other words, it's a bug in their code.


This will be fixed in a future hotfix or service pack. However, they will not / cannot give a date for the fix.

Tuesday, September 13, 2011

SharePoint Inline HTML Editor

One of our clients had very specific requirements for the way in which their editors manage the main body content of a page. Here is some background:

With the previous version of SharePoint (MOSS 2007), page editors could edit page content using a Rich Text editor that sat above the content field. This is shown below:

MOSS RichText Editor

With SharePoint 2010, the Ribbon provides the editing functionality, as shown below:

Ribbon Editor

Even though our client is using SharePoint 2010, they wanted to use the MOSS-style page editor, rather than the Ribbon. This was for a subset of editors, on one specific site.

One way to solve this is to switch the User Interface (UI) version of the site from "4", to "3" e.g. switch from the SharePoint 2010 UI to the MOSS UI. This is done via the SPWeb.UIVersion property.

We didn't want to change the UI version so in the end, the solution was to:

1) Create a custom edit form.
2) Change the control used to edit the page content from SharePoint:FormField to SharePoint:InputFormTextBox

The InputFormTextBox has some properties that allow Rich Text, which are shown below:

<SharePoint:InputFormTextBox TextMode="MultiLine" Rows="6" RichText="true" RichTextMode="Compatible" runat="server" />

Friday, September 9, 2011

SharePoint 0x810200c6 List Validation Failed

We use custom code to create a new Publishing Page:

SPWeb currentWeb = SPContext.Current.Web;

PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(currentWeb);

PublishingPage page = publishingWeb.GetPublishingPages().Add(newPageName, newPageLayout);

This was failing with the error:

<nativehr>0x810200c6</nativehr><nativestack></nativestack>List data validation failed.

The error was caused because the Pages library had validation applied to it, which validated two date fields. The formula for the validation was:

=[Start Date and Time]<[End Date and Time]

When the page was created in code, the validation was fired, which failed because the two date fields are initially empty.

The solution to the problem was to change the validation formula to handle the initial values e.g.

=[Start Date and Time]<=[End Date and Time]

Tuesday, September 6, 2011

SharePoint The document contains invalid utf-8 encoded characters

We used SharePoint to index a website and got the message "The document contains invalid utf-8 encoded characters".

To fix this, modify the target site and replace special characters with their encoded equivalent. For example, replace any £ characters with &pound;. The same is true for ©, which should be replaced with &copy, etc.

Use the W3C validator to identify encoding issues.