Hi,
I got error as “Please try again.<nativehr>0x80004005</nativehr><nativestack></nativestack>”
I have tried with this below code,when I’m adding item to list.
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace EventReceivers1.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item is being updated.
/// </summary>
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
}
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdding(properties);
try
{
bool allowed = checkItem(properties);
if (!allowed)
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = “The Job is defined in the Employee Definition List”;
properties.Cancel = true;
}
}
catch (Exception ex)
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = ex.Message;
properties.Cancel = true;
}
}
bool checkItem(SPItemEventProperties properties)
{
string empTitle = properties.AfterProperties[“Title”].ToString();
bool allowed = false;
SPWeb empweb = null;
SPList empdeflist;
SPUser privilegedAccount = properties.Web.AllUsers[@”SPSERVER0\user1″];
SPUserToken privilegedToken = privilegedAccount.UserToken;
try
{
using (SPSite site = new SPSite(properties.Web.Url, privilegedToken))
{
using (SPWeb web = site.OpenWeb())
{
empweb = web.Webs[“practice”];
empdeflist = empweb.Lists[“Employement”];
foreach (SPListItem item in empdeflist.Items)
{
if (item[“Title”].ToString() == empTitle)
{
allowed = true;
break;
}
}
}
} return allowed;
}
finally
{
empweb.Dispose();
}
}
}
}
I don’t know where I’ve done mistake.Give me if any ideas.
Thanks,
Manju
Attached source adds items to the List.
Strongly encourage to refer number of Microsoft’s free Training resources for SharePoint, Nik has composed of them at http://nikpatel.net/2013/10/29/best-free-online-video-training-available-for-sharepoint-2013-and-office-365-professionals/
*Note that the attached source has been tested successfully.