Pages

Wednesday, January 27, 2016

"Invalid text value. A text field contains invalid data. Please check the value and try again." Error at SPListItem.Update() in SharePoint

When developing sharepoint solutions you may have experienced this common issue while inserting or updating items in sharepoint lists programmatically.

This exceptions occurs when trying to insert or update a column in "Single line of text" type with a value which contains more than 255 characters.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.InteropServices.COMException: 

Invalid text value

A text field contains invalid data. Please check the value and try again.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish)
   at Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents)
   at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents)
   at Microsoft.SharePoint.SPListItem.Update()


To fix this error, you have to limit the value which you are trying to update in "Single line of text" column to 255 characters or change the type of column to "Multi lines of text". 

Note: "Multi lines of text" field has defined in sharepoint as a 'Note' type and this is stored in the the DB as a ntext sql type.In the SQL type can store 2GB of char data, that's 1,073,741,823 characters.

No comments:

Post a Comment