Saturday, February 27, 2010

Ohh Jesus!!! What does this means... "Invalid text value. A text field contains invalid data. Please check the value and try again."

You may get the following exception when calling the Update method of the SPListItem class:

Microsoft.SharePoint.SPException was caught
Message="Invalid text value\n\nA text field contains invalid data. Please check the value and try again."

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()

This occurs when the value you supplied for a text field is larger than 255 characters. To address the problem, store less text in the field or change the field type from text to note.

Tuesday, February 2, 2010

How to get detailed COM Exception error message coming in SP2, MOSS 2007

To get detailed COM Exception error message in SP2, MOSS 2007, you need to implement the following application error handler that writes it to the browser screen (Otherwise, we can only see the detailed error message in the server application log recorded as a warning) :

protected void Application_Error(object sender, EventArgs e)
Exception ex = Server.GetLastError().GetBaseException();
"MESSAGE: " + ex.Message +
"SOURCE: " + ex.Source +
"FORM: " + Request.Form.ToString() +
"QUERYSTRING: " + Request.QueryString.ToString() +
"TARGETSITE: " + ex.TargetSite +
"STACKTRACE: " + ex.StackTrace);

Microsoft.SharePoint.SPException : "Cannot complete this action.\n\nPlease try again."

Today I got the "Cannot complete this action.\n\nPlease try again." exception when trying to save data in a Document Library. The full exception is:

Microsoft.SharePoint.SPException was caught
Message="Cannot complete this action.\n\nPlease try again."
at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
at Microsoft.SharePoint.SPListItemCollection.Undirty()
at Microsoft.SharePoint.SPBaseCollection.System.Collections.IEnumerable.GetEnumerator()
at XXXXX.SharePoint.XXXXXX.XX_XXX_FormUC.SaveOrSubmitSOW(String strSaveOrSubmit)

And the line from which it has been thrown is:

foreach (SPListItem objItem in objSPList.GetItems(objSPQuery))

The solution to my case is pretty peculiar one!! The Columns with type Hyperlink was not working properly. You need to delete those columns and create again. If then also it doesnt work, change them to text mode and handle the hyperlink functionality in the code behind file.