troubleshooting Question

Invalid data has been used to update the list item. The field you are trying to update may be read only.

Avatar of mshaji
mshajiFlag for India asked on
Microsoft SharePoint
3 Comments1 Solution2459 ViewsLast Modified:

I have SharePoint blog and I created a custom web part to add the comments for a new post. But when i add comment item by using this web part then its giving an error "Invalid data has been used to update the list item. The field you are trying to update may be read only."

Please see the attached code here

Does any one have an Idea!

regards
string DURL = "http://myURL/";
                        using (SPSite site = new SPSite(DURL))
                        {
                            using (SPWeb web = site.OpenWeb())
                            {
                                web.AllowUnsafeUpdates = true;
                                SPList listLook = web .Lists ["Posts"];
                                SPList list = web.Lists["Comments"];
                                SPListItem Item1 = list.Items.Add();
                                Item1["Title"] = "My testing title";
                               
                                Item1.Fields["Post Id"].ReadOnlyField = false;
                                Item1["Post Id"] = 1;
                                Item1.Update();
                                Item1.Fields["Post Title"].ReadOnlyField = true;
                                Item1.Fields["Post Id"].ReadOnlyField = true; 
                            }
                        }

Open in new window

ASKER CERTIFIED SOLUTION
mshaji

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros