Showing posts with label Add new list row using Object Model is sharepoint list. Show all posts
Showing posts with label Add new list row using Object Model is sharepoint list. Show all posts

Tuesday, 13 May 2014

Add new list row using Object Model is sharepoint list

private void updateSharePoint(NewSSP_SubmitBLLFields objNewSSP, stringstrNotifiers)
{ SPSite siteCollection = null;
SPWeb topLevelSite = null;


string strNewXRef = String.Empty;
bool blnNoError = true;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
siteCollection = newSPSite(System.Configuration.ConfigurationManager.AppSettings["SPDocumentLibrary"].ToString());
topLevelSite = siteCollection.AllWebs[ConfigurationManager.AppSettings["TopLevelSite"].ToString()];
});
topLevelSite.AllowUnsafeUpdates = true;
SPList list = topLevelSite.Lists[ConfigurationManager.AppSettings["ListName"].ToString()];




// Create List Item
SPListItem objListItem = list.Items.Add();
objListItem["Title"] = objNewSSP.Title;
objListItem["SSP #"] = strRetSSPID.ToString();

string strUserName = Session["FullName"].ToString();
for (int i = 0; i 0)
{
objListItem["Estimated Completion Date"] = txtEstimateComplitionDate.Text;
}
objListItem["Request Date"] = DateTime.Today.ToShortDateString().ToString();
objListItem["Timing"] = txtTiming.Text;
objListItem["Cost"] = txtCost.Text;
objListItem["How Affect Product"] = txtHowAffectProduct.Text;





string strNList = string.Empty;
if (lstnotification.Items.Count > 0)
{

for (int i = 0; i < lstnotification.Items.Count; i++)
{

if(!string.IsNullOrEmpty(lstnotification.Items[i].ToString()))
{
strNList = lstnotification.Items[i].ToString() + ";";
}
}
objNewSSP.NotificationList = strNList.ToString();
objListItem["NotificationList"] = strNList;
}
objListItem.Update();
topLevelSite.AllowUnsafeUpdates = false;
UploadSSPFiles();
hdnDupTitle.Value = "Yes";
}





catch (Exception ex)
{
blnNoError = false;
lblMsg.Text = "Error " + ex.StackTrace.ToString() + " While Updating Sharepoint List";


// lblSuccessMsg.Text = "";
}
finally
{
if (blnNoError)
{
lblMsg.Text = "";

// lblSuccessMsg.Text = "Document has been reserved successfully";
txtComments.Enabled = false;
//btnSubmit.Enabled = false;
}
}
siteCollection.Dispose();
topLevelSite.Dispose();
if (blnNoError)
{

//Response.Redirect("Confirm.aspx?id=9&SSPID=" + strRetSSPID);
spnSSPID.InnerText = strRetSSPID.ToString();
ScriptManager.RegisterStartupScript(this, Page.GetType(), "","ShowDivLayer('shadow','divShowSSPID');", true);
}
}
http://www.infoitweb.com/Common/Articles.aspx?TypeID=11&ContentID=139