Welcome to MSDN Blogs Sign in | Join | Help

"Invalid data has been used to update the list item. The field you are trying to update may be read only" - when updating BEGIN - END fields in an event list through Object Model code

When updating the "Begin" or the "End" datetime fields in a SharePoint 2003/2007 event list, the error "Invalid data has been used to update the list item. The field you are trying to update may be read only" is seen at the point where Update() method is called on the list item object.

 

SharePoint somehow seems to look for both the BEGIN – END parameter when the Update() method is called.  If either is not provided, you’ll see the above error.

 

Values for both "Begin" and "End" should be specified before calling the Update() method of the List item object.  If either one of them needs to be updated with a new value, the other also needs to be set to a datetime value to prevent this error.

 

Set both the value through the code before calling the Update() method on the list item object.

 

Code that'll error out:

 

DateTime dtNow = DateTime.Now;

SPSite site = new SPSite("http://sharepoint");

SPWeb web = site.OpenWeb();

SPListItem listItem = web.Lists["test_list"].Items[0];

listItem["Begin"] = dtNow;

listItem.Update(); // this call will error out

 

To get past this error in this specific scenario, modify the code something like the below:

 

DateTime dtNow = DateTime.Now;

SPSite site = new SPSite("http://sharepoint");

SPWeb web = site.OpenWeb();

SPListItem listItem = web.Lists["test_list"].Items[0];

listItem["Begin"] = dtNow;

listItem["End"] = dtNow.AddDays(5);

listItem.Update(); // this call will pass through

Published Sunday, April 01, 2007 11:24 PM by sridhara
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Tuesday, October 02, 2007 9:04 AM by Michael

# re: "Invalid data has been used to update the list item. The field you are trying to update may be read only" - when updating BEGIN - END fields in an event list through Object Model code

Sridhar,

I am getting this error with Sharepoint 2003, and in my list, I don't have the fields "Begin" and "End"??  I'm a little confused, I define the fields in my Sharepoint list.  So, why are you saying update "Begin" and "End"?  Does every Sharepoint list have a "Begin" and "End"?

Thanks for any help...

Regards..

Wednesday, October 17, 2007 4:12 AM by Sowmya

# re: "Invalid data has been used to update the list item. The field you are trying to update may be read only" - when updating BEGIN - END fields in an event list through Object Model code

Is it possible to update "Created By" and "Modified By" field from .net.when i tried updating it is throwing this error "+ InnerException {"Invalid data has been used to update the list item. The field you are trying to update may be read only."} System.Exception {System.Runtime.InteropServices.COMException}

"

Thursday, October 25, 2007 11:43 AM by aman tur

# re: "Invalid data has been used to update the list item. The field you are trying to update may be read only" - when updating BEGIN - END fields in an event list through Object Model code

I'm trying to add a custom list item from aspx page. I'm passing all required data and not touching any readonly field still i'm getting this error.

Thursday, July 24, 2008 2:37 AM by Montanus

# re: "Invalid data has been used to update the list item. The field you are trying to update may be read only" - when updating BEGIN - END fields in an event list through Object Model code

Just want to share my findind, this was also my problem when I'm attaching a file to an item and I'm getting a Data is invalid error. I tried everything I've found including on this blog. And I found out that, that the cause of the error is... that the actual is zero byte. So, to prevent the error mention I have to check

byte[] b = item.File.openBinary();

if(b.length==0)

I hope, I can be help for someone.

Tony

Friday, June 12, 2009 4:36 AM by hd

# re: "Invalid data has been used to update the list item. The field you are trying to update may be read only" - when updating BEGIN - END fields in an event list through Object Model code

i'm getting similar error. i finally figured out that in my list i have two fields which takes LOOK UP VALUES. Is there anyway i can add values to these look up fields also

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker