Update Sharepoint List Item

前端 未结 4 940
耶瑟儿~
耶瑟儿~ 2020-12-15 00:31

I got following error...

System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.SPListItem.get

4条回答
  •  庸人自扰
    2020-12-15 00:59

    If you're trying to alter values for a just inserted list item, you should go with:

    SPList list = web.Lists["ListName"];
    //SPListItem item = list.Items.Add();
    //item["PercentComplete"] = .45; // 45%
    //item.Update();
    
    SPListItemCollection items = list.GetItems(new SPQuery()
    {
        Query = @"
                    
                       
                       Desigining
                    
                  "
    });
    
    foreach (SPListItem item in items)
    {
        item["PercentComplete"] = .45; // 45%
        item.Update();
    }
    

    You just need to use list.Items[uniqueId] or faster list.GetItemByUniqueId(uniqueId) if you needs to find a particular item to update; what can be accomplished by using SPQuery class.

提交回复
热议问题