I am having a sharepoint sitecollection which has two sites say site1 and site2.
I have a user, have contribute premission in site1 and read permission in site2.
I wrote a event receiver on item added in a list1 in site1 for moving the same record in a list2 in site2.
public override void ItemAdded(SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = properties.OpenSite())
{
using (SPWeb web = site.OpenWeb("/site2"))
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["List2"];
SPListItem item = list.Items.Add();
item["Title"] = "test";
item.Update();
web.AllowUnsafeUpdates = false;
}
}
});
}
I tried with RunWithElevatedPrivileges even AllowUnsafeUpdates but Unfortunately it is not working in my case. on Update() it throws UnauthorizedAccessException.
{System.UnauthorizedAccessException:
<nativehr>0x80070005</nativehr><nativestack></nativestack>
I am using sharepoint 2010 sp1 with aug2012 cumulative updates.
using
clause for the SPWeb as disposing the owningSPSite
will dispose any webs opened from it, and you should safely revert theAllowUnsafeUpdates
in afinally
block in an outer try/finally block. Right now, if it blows up you may leave the unsafe flag active. – x0n