Thursday, July 20, 2017

Adding Items Into A SharePoint list



protected void Page_Load(object sender, EventArgs e)
    {
       public string Pid = Request.QueryString["pid"];
        if (Pid != null)
        {
 
     try  
            {  
                using(SPSite site = new SPSite(SPContext.Current.Web.Url))  
                {  
                    using(SPWeb web = site.OpenWeb())  
                    {  
                        SPList list = web.Lists.TryGetList("List Name");  
                        if(list!=null)  
                        {  
                            SPListItem NewItem = list.Items.Add();  
                            {  
                                web.AllowUnsafeUpdates = true;  
                                NewItem["Coulm1"] = Pid;  
                                NewItem["Coulm2"] =txt.something;  
                                NewItem["Colum3"] =txtaddr.Text;  
                               
                                NewItem.Update();  
                                Alert.Text = "Successful";  
                                 
                            }  
                        }  
                        else  
                        {  
                            Alert.Text = " not found";  
                        }  
                    }  
                }  
              
             
            }  
            catch(Exception ex)  
{  
                Alert.Text = ex.Message.ToString();  
}    
 
 }
   

          
}

No comments:

Post a Comment