SPListItem.Update() throws exception when trying to update Title. 255 char limit issue with encoding
It seems that I have an issue with encoding. The field max width is 255 chars 开发者_如何学JAVAand 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?
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.
精彩评论