Search This Blog

Wednesday, March 23, 2016

How to find the ListItemId is exist or not in Sharepoint List Programatically?



                using (SPSite oSite = new SPSite("http:\\serverName\site\TestProject"))
                {
                    using (SPWeb oWeb = oSite.OpenWeb())
                    {
                        SPList oList = oWeb.Lists.TryGetList("TestList");
                        if (oList != null)
                        {
                            var listEnumeration = oList.Items.OfType<SPListItem>();
                            bool IsExist = listEnumeration.Any(p => p.ID == 1);
                            if (IsExist)
                            {
                                //List Item id exists in List
                            }
                            else
                            {
                                //List Item id doesn't exists in List
                            }
                        }

                    }
                 }

No comments:

Post a Comment