WebPart is raising the following error "Invalid data has been used to update the list item.The field you are trying to update may be read only"

I have created a farm solution and then i deploy it to SharePoint server, the code looks as follow, and i use it to update a page info values (as the current page values represents old info):-
[ToolboxItemAttribute(false)]
public partial class VisualWebPart1 : WebPart
// Uncomment the following SecurityPermission attribute only when doing Performance Profiling using
// the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
// for production. Because the SecurityPermission attribute bypasses the security check for callers of
// your constructor, it's not recommended for production purposes.
// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
public VisualWebPart1()
protected override void OnInit(EventArgs e)
base.OnInit(e);
InitializeControl();
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists["Pages"];
web.AllowUnsafeUpdates = true;
foreach (SPListItem items in list.Items)
items["Author"] = "SharePoint";
items["Created"] = "01/08/2014 01:44 PM";
items.Update();
list.Update();
web.AllowUnsafeUpdates = false;
protected void Page_Load(object sender, EventArgs e)
but when i try adding this web part to a page i got the following error:-
Invalid data has been used to update the list item.The field you are trying to update may be read only
so can anyone advice?

i only changed lines bitween 
web.AllowUnsafeUpdates = true;
and
web.AllowUnsafeUpdates = false;
and other parts of code remains without change
so it will updates all pages in current web
yaşamak bir eylemdir

Similar Messages

  • "SharePoint list itme update error : Invalid data has been used to update the list item. The field you are trying to update may be read only."

    Hi Everyone,
    i am facing one problem ...
    when i am updating an SharePoint List item, it is throwing above error....
    This is my code......
     try
                    tbl = getListDateTable("NCR");
                    DataTable dt = tbl;
                    oWebsite = mysite.OpenWeb();
                    oList = oWebsite.Lists["NCR"];
                    SPListItem itemToUpdate = null;
                    foreach (SPListItem listItem in oList.Items)
                        listItem.Update();
                        workOrderID = Convert.ToInt32(txtTitle.Text);
                        itemToUpdate = listItem;
                    //SPListItem itemToUpdate = oList.GetItemById(workOrderID);
                    //itemToUpdate.Fields["Title"].ReadOnlyField = false;
                    //string str = ddlStatus.SelectedValue;
                    itemToUpdate["Title"] = txtTitle.Text;
                    itemToUpdate["JobNumber"] = txtJobNumber.Text;
                    itemToUpdate["PartNumber"] = txtPartNumber.Text;
                    itemToUpdate["PartDescription"] = txtPartDescription.Text;
                    //itemToUpdate["RequiredBy"] = txtRequiredBy.Text;
                    itemToUpdate["ReportedBy"] = txtReportedBy.Text;
                    itemToUpdate["WrittenBy"] = txtWrittenBy.Text;
                    //itemToUpdate["DateOpened"] = txtDateOpened.SelectedDate;
                    //itemToUpdate["DateClosed"] = txtDateClosed.SelectedDate;
                    itemToUpdate.Update();
                    oList.Update();
                   // bind();
                catch (Exception ex)
                    throw ex;
    Thanks
    viswanath

    Hi Viswanath,
    If you are using People/User Type Field Column then use below code methord
    SPUser user = web.EnsureUser(loginName);
    item["UserTypeFieldName"] = user;
    Lookup Type Field Column then use below code methord
    public static SPFieldLookupValue GetLookupFieldFromValue(string lookupValue,string lookupSourceColumn, SPList lookupSourceList)
    SPFieldLookupValue value = null;
    SPQuery query = new SPQuery();
    query.Query = "<Where><Eq><FieldRef Name='" + lookupSourceColumn + "'/><Value Type='Text'>" + lookupValue + "</Value></Eq></Where>";
    SPListItemCollection listItems = lookupSourceList.GetItems(query);
    if(listItems.Count > 0 )
    value = new SPFieldLookupValue(listItems[0].ID,lookupValue);
    return value;
    item["LookupField"] = GetLookupFieldFromValue(lookupfieldValue, lookupSourceColumn, listName);
    Please mark the replies as answers if they help or unmark if not.

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

    Trying to follow Serge Luca's Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007.  http://sergeluca.spaces.live.com/blog/cns!E8A06D5F2F585013!859.entry
    I have an onWorkflowActivated, followed by an ifElse condition and a log to history.
    In the IfElse, each branch has a code segment, that trys to update the status column in the list that the workflow is attached to.
    private void Authorize_ExecuteCode(object sender, EventArgs e)
    // tried serveral methods
    WorkflowProperties.Item["Status"] = "Automatically Approved";
    // tried all of the following (one at a time)
    item.update();
    WorkflowProperties.Item.Update();
    WorkflowProperties.Item.SystemUpdate();
    //tried this as well.
    Microsoft.SharePoint.SPListItem item = WorkflowProperties.Item;
    item["Status"] = "Automatically Approved";
    item.Update() ;
    On the update call I keep getting "Invalid data has been used to update the list item. The field you are trying to update may be read only."
    Could someone explain how to update "Status" column of the list item that the workflow is working on?
    Thank you very much.
    Bill
     

    Hi:
    you can do the following:
    add the following code to the workflow.xml file (under the MetaData section)
    Code Snippet
    <ExtendedStatusColumnValues>
    <StatusColumnValue>Branch1</StatusColumnValue>
    <StatusColumnValue>Branch2</StatusColumnValue>
    </ExtendedStatusColumnValues>
    then add 2 SetState activities one in each branch of the IfElse.
    for the code behind of setState1 (branch1) write the following code:
    Code Snippet
    state = Convert.ToInt32(SPWorkflowStatus.Max);
    for setState2 (branch2) write the following:
    Code Snippet
    state = Convert.ToInt32(SPWorkflowStatus.Max) + 1;
    where state is the variable assigned to the field State in the properties of the SetState(design lever), or instead of state u can use the following code:
    Code Snippet
    ((SetState)sender).State
    where sender is the object sent through the function parameter.
    hope this answered your question
    Best Regards

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

    Hi.
    I am getting below error while adding value to look-up field.
    Invalid data has been used to update the list item. The field you are trying to update may be read only.
    I have tried many forums ans post but didn't come to know what's the root cause of issue. I am also posting Code for creating and adding lookup field.
    CAML to create lookup field (It works Fine)
    string lkproductNumber = "<Field Type='Lookup' DisplayName='Product Number' StaticName='ProductNumber' ReadOnly='FALSE' List='" + pNewMaster.Id + "' ShowField='Product_x0020_Number' />";
    Code to insert value to lookup field
    ClientContext client = new ClientContext(SiteUrl);
    client.Load(client.Web);
    client.Credentials = new NetworkCredential(this.UserName, this.Password, this.Domain);
    // Lookup Lists
    List pmList = client.Web.Lists.GetByTitle("Product_Master");
    //List Conatining Lookup Columns
    List piList = client.Web.Lists.GetByTitle("Product_Inventory");
    client.Load(piList);
    query.ViewXml = "<View/>";
    ListItemCollection collection = pmList.GetItems(query);
    client.Load(collection);
    client.ExecuteQuery();
    int prodid=0;
    foreach (ListItem item in collection)
    if (Convert.ToString(item["Product_x0020_Number"]) == ProductNumber)
    { prodid = Convert.ToInt32(item["ID"]); }
    ListItem piItem = piList.AddItem(new ListItemCreationInformation());
    piItem["Product_x0020_Number"] = new FieldLookupValue() { LookupId = prodid };
    piItem.Update();
    client.ExecuteQuery();
    Exception Detail
    Microsoft.SharePoint.Client.ServerException was caught
    Message=Invalid data has been used to update the list item. The field you are trying to update may be read only.
    Source=Microsoft.SharePoint.Client.Runtime
    ServerErrorCode=-2147352571
    ServerErrorTypeName=Microsoft.SharePoint.SPException
    ServerStackTrace=""
    StackTrace:
    at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
    at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
    at WebServiceProviders.ClientServices.NewProductInventory() in Z:\.............ClientServices.cs:line 889
    InnerException:
    Quick response is highly appreciated.
    Thanks
    Mehar

    Try some thing like below,
    your data value that needs to be update should be in this format "ID of the lookup";#"Title of the Lookup" 
    For example,
    listItem["Product_x0020_Number"]
    = "1;#iPhone";
    listItem["Product_x0020_Number"]
    = "2;#Mobile";
    Hope this helped you....

  • SharePoint returned the following error: Invalid URI: The URI is empty.

    When I try to add Site Feed (News Feed) in the SharePoint 2013, I get
    “SharePoint returned the following error: Invalid URI: The URI is empty. Contact your system administrator for help in resolving
    this problem” error message. Could you please provide me a solution or cause of this issue?
    Many Thanks.

    Hi Aruna
    To resolve this, You have to create and configure my site i.e.
    Created a new web app for my site
    Created the my site host site collection as the root
    Provisioned the User Profile Service App
    Configured the My Site URL in Setup My Site in User Profile Service App
    IISRESET
    Each environment is different and unique, ULS Log viewer is the key to identify and troubleshoot this.
    For more details follow the link
    SharePoint 2013 Invalid URI: The URI is empty
    Indul Hassan
    Microsoft Community Contributor
    http://www.indulhassan.com
    You Snooze.. You Lose !!

  • [Execute SQL Task] Error: Executing the query "DECLARE_@XMLA nvarchar(3000) ,__@DateSerial nvarch..." failed with the following error: "Incorrect syntax near '-'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly,

    Hi
    DECLARE @XMLA nvarchar(3000)
    , @DateSerial nvarchar(35);
    -- Change date to format YYYYMMDDHHMMSS
    SET @DateSerial = CAST(GETDATE() AS DATE);
    --SELECT @DateSerial
    Set @XMLA = 
    N' <Batch xmlns="http://schemas.microsoft.com/analysis services/2003/engine">
     <ErrorConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2"
    xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200"
    xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200">
    <KeyErrorLimit>-1</KeyErrorLimit>
    <KeyNotFound>IgnoreError</KeyNotFound>
    <NullKeyNotAllowed>IgnoreError</NullKeyNotAllowed>
     </ErrorConfiguration>
     <Parallel>
    <Process xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2"
    xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200"
    xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
     <Object>
     <DatabaseID>MultidimensionalProject5</DatabaseID>
     <CubeID>giri</CubeID>
     <MeasureGroupID>Fact Internet Sales</MeasureGroupID>
     </Object>
     <Type>ProcessFull</Type>
     <WriteBackTableCreation>UseExisting</WriteBackTableCreation>
     </Process>
      </Parallel>
    </Batch>';
    EXEC (@XMLA) At SHALL-PCAdventureWorksDw ;
     iam executive the    query when iam getting below error.
      [Execute SQL Task] Error: Executing the query "DECLARE
    @XMLA nvarchar(3000)
    , @DateSerial nvarch..." failed with the following error: "Incorrect syntax near '-'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set
    correctly, or connection not established correctly. 
     how to solve this error;
     please help me

    What are you trying to do? What sort of data source is  SHALL-PCAdventureWorksDw?
    When you use EXEC() AT, I would execpt to see an SQL string to be passed to EXEC(), but you are passing an XML string????
    If you explain why you think this would work in the first place, maybe we can help you.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • I get the following error when formatting a external hard drive. Partition failed with the error:  POSIX reports: The operation couldn't be completed. Cannot allocate memory

    I get the following error when formatting a external hard drive.
    Partition failed with the error: 
    POSIX reports: The operation couldn’t be completed. Cannot allocate memory
    I have a Macbook pro 13" A1278. I purchased it around december 2010. I have a HHD 3.5" drive desktop select II 1.5TB. I purchased it around Febuary/March 2011 to use with my Macbook pro. I formatted it and moved all my files to there, I got it so my macbook's hard drive wouldn't brake and I lose everything on my macbook.
    Is there any fixes?

    First, try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until the screen blacks out or you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."

  • When downloading itunes onto my windows 7 pc I get the following error message "this installation package could not be opened verify that the package exists and that you can access it"

    I am having trouble downloading Itune, icloud etc onto my Windows 7 PC and keep getting the following error message "this installation pack could not be opened, verify that the package exists and that you can access it"

    tried downloading the quicktime installer, I get the same message with it too

  • While partitioning in Lion 10.8, I get the following error message: I have been attempting to partition a 2 GB hard drive that I just formatted using the Disk Utilty in Mountain Lion (10.8) and get the following error message:  DiskManagementTool has died

    I have been attempting to partition a 2 GB hard drive that I just formatted using the Disk Utilty in Mountain Lion (10.8) and get the following error message:
    DiskManagementTool has died. Disk Utility will need to be restarted.  The log shows the following:
    2012-09-10 11:20:51 -0700: Preparing to partition disk: “HitachiG ST Media”
    2012-09-10 11:20:51 -0700:      Partition Scheme: GUID Partition Table
    2012-09-10 11:20:51 -0700:      2 partitions will be created
    2012-09-10 11:20:51 -0700:
    2012-09-10 11:20:51 -0700:      Partition 1
    2012-09-10 11:20:51 -0700:           Name          : “Alex's External Storage”
    2012-09-10 11:20:51 -0700:           Size          : 1.5 TB
    2012-09-10 11:20:51 -0700:           File system     : Mac OS Extended (Journaled)
    2012-09-10 11:20:51 -0700:           Do not erase contents
    2012-09-10 11:20:51 -0700:
    2012-09-10 11:20:51 -0700:      Partition 2
    2012-09-10 11:20:51 -0700:           Name          : “Alex's External Storage 2”
    2012-09-10 11:20:51 -0700:           Size          : 500.05 GB
    2012-09-10 11:20:51 -0700:           File system     : Mac OS Extended (Journaled)
    2012-09-10 11:20:51 -0700:
    2012-09-10 11:20:51 -0700: Beginning partition operations
    2012-09-10 11:20:51 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:52 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:52 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:52 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:55 -0700: Disk Utility started.
    Does anyone have any thoughts?  Cant find anything on the web with this

    I have been attempting to partition a 2 GB hard drive that I just formatted using the Disk Utilty in Mountain Lion (10.8) and get the following error message:
    DiskManagementTool has died. Disk Utility will need to be restarted.  The log shows the following:
    2012-09-10 11:20:51 -0700: Preparing to partition disk: “HitachiG ST Media”
    2012-09-10 11:20:51 -0700:      Partition Scheme: GUID Partition Table
    2012-09-10 11:20:51 -0700:      2 partitions will be created
    2012-09-10 11:20:51 -0700:
    2012-09-10 11:20:51 -0700:      Partition 1
    2012-09-10 11:20:51 -0700:           Name          : “Alex's External Storage”
    2012-09-10 11:20:51 -0700:           Size          : 1.5 TB
    2012-09-10 11:20:51 -0700:           File system     : Mac OS Extended (Journaled)
    2012-09-10 11:20:51 -0700:           Do not erase contents
    2012-09-10 11:20:51 -0700:
    2012-09-10 11:20:51 -0700:      Partition 2
    2012-09-10 11:20:51 -0700:           Name          : “Alex's External Storage 2”
    2012-09-10 11:20:51 -0700:           Size          : 500.05 GB
    2012-09-10 11:20:51 -0700:           File system     : Mac OS Extended (Journaled)
    2012-09-10 11:20:51 -0700:
    2012-09-10 11:20:51 -0700: Beginning partition operations
    2012-09-10 11:20:51 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:52 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:52 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:52 -0700: DiskManagementTool has died. Disk Utility will need to be restarted.
    2012-09-10 11:20:55 -0700: Disk Utility started.
    Does anyone have any thoughts?  Cant find anything on the web with this

  • After the most recent iPhoto update, I keep getting the following error: "iPhoto quit unexpectedly while using the Sonix SN9c201 webcam plugin."  This seems to happen after *every* iPhoto update.  Is there a fix on the way?

    After the most recent iPhoto update, I keep getting the following error: "iPhoto quit unexpectedly while using the Sonix SN9c201 webcam plugin."  This seems to happen after *every* iPhoto update.  Is there a fix on the way?

    As you can see below, when I right click, I have no such option.  In the User Account Settings, I'm operating as the "System Administrator".
    Any other suggestions?

  • Muse crashes with the following error, "menuItemBox U32584 has no associates page!"

    I'm trying to remove pages from my menu by exluding them via the page properties.  When I do that Muse crashes with the following error, "menuItemBox U32584 has no associates page!"  Any help is appreciated.

    One or more menu widgets within your site have become out-of-sync with the structure of your site in Plan view. If you send us the file we can repair and return it. Or you could delete and recreate the menu widgets.
    Please send us the .muse file at [email protected] along with a link to this thread. If the file is larger than 20Mb you can use a service like Adobe SendNow, Dropbox, WeTransfer, etc. (If you use a service, please include your return e-mail address in the body of the message, since not all services include it in the sharing invite they send.)
    Thanks.

  • Every time I open Iphoto I get the following message:  "A photo has been found in the iPhoto library that was not imported.  Do you want to import it?  Yes or No"  Any suggestions?

    Every time I open Iphoto I get the following message:  "A photo has been found in the Iphoto library that was not imported.  Does anyone have any suggestions?

    Quit iPhoto and to to the iPhoto library (by default in your pictures folder) - right click (control click) on it and select show package contents - find the folder named import (on importing) and drag it to the desktop - DO NOT MAKE ANY OTHER CHANGES - launch iPhoto and you will be fine.
    Open the import(ing) folder and if there is nothing in it that you need move it to the trash and empty the trash
    LN

  • Adobe Photoshop CS6 won't load on my macbook pro, says "Could not initialize Photoshop because the file was invalid (it has been deleted).

    Adobe Photoshop CS6 won't load on my macbook pro, says "Could not initialize Photoshop because the file was invalid (it has been deleted).

    Tried the preferences, they are not there, tried uninstalling and reinstalling, no love! Any help?

  • I have Windows XP and microsoft outlook with FIrefox as my browser; when I try to open a link in an email I get the following message "This operation has been canceled due to restrictions in effect on this computer. Please contact your system administrato

    I have Windows XP and microsoft outlook with Firefox as my browser; when I try to open a link in an email I get the following message "This operation has been canceled due to restrictions in effect on this computer. Please contact your system administrator"

    Tried that. Unfortunately it did not work.

  • My ipod wont let me buy apps etc... keeps saying this is the first time this device has been used and to sign in and answer security questions. I have had this account for years but cant remember the answer to the security questions. How can i fix it?

    My iPod touch wont let me buy anything, i've beem using this account for a couple of years and now it says that this is the first ime this id has been used on my device... it's not.... and to sign in and answer security questions. i cant remember the answers to the questions. How can i fix this without making a new account and losing all my stuff???

    From a Kappy  post
    The Three Best Alternatives for Security Questions and Rescue Mail
       1. Use Apple's Express Lane.
    Go to https://expresslane.apple.com ; click 'See all products and services' at the
    bottom of the page. In the next page click 'More Products and Services, then
    'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Forgotten Apple
    ID security questions' and click 'Continue'. Please be patient waiting for the return
    phone call. It will come in time depending on how heavily the servers are being hit.
    2.  Call Apple Support in your country: Customer Service: Contact Apple support.
    3.  Rescue email address and how to reset Apple ID security questions.
    A substitute for using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

Maybe you are looking for