internal static bool InsertStudent(StudentBL studentBL)
{
string _siteUrl = SPContext.Current.Site.Url;
string _deplistName = "StudentList";
SPSite _objSite;
SPWeb _objWeb;
SPList _deplist;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (_objSite = new SPSite(_siteUrl))
{
_objSite.AllowUnsafeUpdates = true;
using (_objWeb = _objSite.OpenWeb())
{
_objWeb.AllowUnsafeUpdates = true;
_deplist = _objWeb.Lists[_deplistName];
SPListItem _item = _deplist.Items.Add();
_item["StudentID"] = studentBL.Studentid;
_item["StudentReg"] = studentBL.Regno;
_item["StudentName"] = studentBL.Studentname;
_item["Email"] = studentBL.Email;
_item["Address"] = studentBL.Address;
_item["Photo"] = studentBL.Phonenumber;
_item.Update();
_objWeb.AllowUnsafeUpdates = false;
}
_objSite.AllowUnsafeUpdates = false;
}
}
); return true;
}
------------------------------------------------------------------------------------------
internal static bool DeleteStudent(StudentBL studentBL)
{
string _siteUrl = SPContext.Current.Site.Url;
string _deplistName = "StudentList";
SPSite _objSite;
SPWeb _objWeb;
SPList _deplist;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (_objSite = new SPSite(_siteUrl))
{
_objSite.AllowUnsafeUpdates = true;
using (_objWeb = _objSite.OpenWeb())
{
_objWeb.AllowUnsafeUpdates = true;
_deplist = _objWeb.Lists[_deplistName];
SPListItem _item = _deplist.Items.Add();
_item["ID"] = studentBL.Studentid;
_item.Delete();
_objWeb.AllowUnsafeUpdates = false;
}
_objSite.AllowUnsafeUpdates = false;
}
}
); return true;
}
No comments:
Post a Comment