Note:
When you create a splistitem using SpSecurity Privileges code with person who is having non admin permission then the listitems will be created with system account.
SPWeb currentWeb = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPListItemCollection mycoll = web.Lists["Login"].Items;
SPListItem item = mycoll.Add();
item["Title"] = txtUserName.Text;
item["Password"] = txtPassWord.Text;
item.Update();
txtUserName.Text = "";
txtPassWord.Text = "";
strError += "Record Saved Succesfully";
}
}
});
When you create a splistitem using SpSecurity Privileges code with person who is having non admin permission then the listitems will be created with system account.
SPWeb currentWeb = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(currentWeb.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPListItemCollection mycoll = web.Lists["Login"].Items;
SPListItem item = mycoll.Add();
item["Title"] = txtUserName.Text;
item["Password"] = txtPassWord.Text;
item.Update();
txtUserName.Text = "";
txtPassWord.Text = "";
strError += "Record Saved Succesfully";
}
}
});
No comments:
Post a Comment