SPListItem.Update() throws exception when trying to update Title. 255 char limit issue with encoding

0

It seems that I have an issue with encoding. The field max width is 255 chars and the title is indeed 255 chars, however there are some characters in the title (quotes and angle brackets) that are encoded by SharePoint, pushing the title width over the 255 char limit.

This leaves me in an unsupported state. Updates both via the SP Object model and via the list service. I get the very general exception:

Error Code: 0x80040e21

The operation failed because an unexpected error occurred. (Result Code: 0x80040e21)

Are there options for getting out of this broken state, short of deleting and recreating the content?

sharepoint
sharepoint-2007
splistitem
sharepoint-object-model
asked on Stack Overflow Apr 29, 2011 by Chris Ballance

1 Answer

0

This seems to be an unhandled exception bubbling up from the COM layer instead of being trapped more directly in SPItem. Since there is no validation around assignment to the field, you can assign an invalid value (in this case a value > 255 characters) and the failure occurs when .Update() is called, giving a more vague error than expected.

Workaround: Expand the title by encoding it and trimming as necessary.

answered on Stack Overflow May 26, 2011 by Chris Ballance

User contributions licensed under CC BY-SA 3.0