I have got two lists. I must do synchronize this list, but one have got only 3 columns, and secound list have got 3 columns too, but have got more columns with hidden value. I done synchronizing adding, but I must do ItemUpdated to. Because if i change a value in 3 columns in first list it should change in secaund list. Adding was done by this code Event Receiver:
public override void ItemAdded(SPItemEventProperties properties)
{
this.EventFiringEnabled = false;
base.ItemAdded(properties);
if (properties.List.Title == "Jawna")
{
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList lstOtherList = properties.Web.Lists["Niejawna"];
SPListItem item = lstOtherList.Items.Add();
web.AllowUnsafeUpdates = true;
item["Title"] = properties.AfterProperties["Title"];
item["B"] = properties.AfterProperties["B"];
item["Status"] = properties.AfterProperties["Status"];
item.Update();
}
}
}
if (properties.List.Title == "Niejawna")
{
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList lstOtherList = properties.Web.Lists["Jawna"];
SPListItem item = lstOtherList.Items.Add();
web.AllowUnsafeUpdates = true;
item["Title"] = properties.AfterProperties["Title"];
item["B"] = properties.AfterProperties["B"];
item["Status"] = properties.AfterProperties["Status"];
item.Update();
}
}
}
this.EventFiringEnabled = true;
}
How to done the same with items update ? I think it should be the Caml Query, or linq query. But how ? Please help me. To change only this element wchich have got 3 Colums the same as in first List.
Updated Question:
I write the code:
public override void ItemUpdated(SPItemEventProperties properties)
{
this.EventFiringEnabled = false;
base.ItemUpdated(properties);
if (properties.List.Title == "Jawna")
{
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList lstOtherList = properties.Web.Lists["Niejawna"];
string fieldA = properties.ListItem["Title"].ToString();
string fieldB = properties.ListItem["B"].ToString();
string fieldStatus = properties.ListItem["Status"].ToString();
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Field A'/><Value Type='Text'>" + fieldA + "</Value></Eq></Where>";
SPListItemCollection items = lstOtherList.GetItems(query);
SPListItem item = items[0];
item["Title"] = properties.ListItem["Title"];
item.Update();
}
}
}
this.EventFiringEnabled = true;
}
And I getting now this error:
One or more field types are not installed properly. Go to the list settings page to delete these fields.