Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Submit to List Code Error

$
0
0

Hi, I have coded a button in my IP2010 Library Form that will iterate through a repeating table and submit those values line by line to a list in SP2010.  However, after multiple attempts to update and fix the code, I get the following error:

"Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object.)"

Here is the code:

public void InternalStartup()
        {
              ((ButtonEvent)EventManager.ControlEvents["CTRL277_5"]).Clicked += new ClickedEventHandler(Submit);
        }
public void Submit(object sender, ClickedEventArgs e)
        {
            using (SPSite site = new SPSite("http://SharePoint/MySite")) //SPContext.Current.Site
            {
                if (site != null)
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        web.AllowUnsafeUpdates = true;
                        SPList fetchlist = web.Lists["My List"];
                        if (fetchlist != null)
                        {
                            // Retrieve the rows of the repeating table
                            XPathNavigator root = MainDataSource.CreateNavigator();
                            XPathNodeIterator rows = root.Select("/my:myFields/my:dataFields/my:repeatingGroup", NamespaceManager);
                            XPathNodeIterator rows1 = root.Select("/my:myFields/my:dataFields/my:repeatingSection", NamespaceManager);
                            while (rows.MoveNext())
                            {
                                // Retrieve the title
                                string title = rows.Current.SelectSingleNode("my:FieldName", NamespaceManager).Value;
                                if (title != string.Empty)
                                {
                                    //string fieldValue1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:dataFields/my:repeatingGroup/my:FieldName", NamespaceManager).Value;
                                    string fieldValue1 = rows.Current.SelectSingleNode("my:FieldName", NamespaceManager).Value;
                                    string fieldValue2 = rows.Current.SelectSingleNode("my:FieldType", NamespaceManager).Value;
                                    string fieldValue3 = rows.Current.SelectSingleNode("my:Location", NamespaceManager).Value;
                                    string fieldValue4 = rows.Current.SelectSingleNode("my:UserID", NamespaceManager).Value;
                                    string fieldValue5 = rows.Current.SelectSingleNode("my:CurrentDate", NamespaceManager).Value;
                                    string fieldValue6 = rows.Current.SelectSingleNode("my:NewDate", NamespaceManager).Value;
                                    string fieldValue7 = rows.Current.SelectSingleNode("my:AlternateDate", NamespaceManager).Value;
                                    string fieldValue8 = rows.Current.SelectSingleNode("my:NewStatus", NamespaceManager).Value;
                                    string fieldValue9 = rows1.Current.SelectSingleNode("my:FirstReason", NamespaceManager).Value;
                                    string fieldValue10 = rows1.Current.SelectSingleNode("my:SecondReason", NamespaceManager).Value;
                                    string fieldValue11 = rows1.Current.SelectSingleNode("my:ThirdReason", NamespaceManager).Value;
                                    string fieldValue12 = rows1.Current.SelectSingleNode("my:FinancialInformed", NamespaceManager).Value;
                                    string fieldValue13 = rows1.Current.SelectSingleNode("my:NewNotice", NamespaceManager).Value;
                                    string fieldValue14 = rows1.Current.SelectSingleNode("my:AssociateRegion", NamespaceManager).Value;
                                    string fieldValue15 = rows1.Current.SelectSingleNode("my:PrimaryReason", NamespaceManager).Value;
                                    string fieldValue16 = rows1.Current.SelectSingleNode("my:SecondaryReason", NamespaceManager).Value;
                                    string fieldValue17 = rows.Current.SelectSingleNode("my:NewFieldType", NamespaceManager).Value;
                                    SPListItem newitem = fetchlist.AddItem();
                                    newitem["Field_x0020_Name"] = fieldValue1;
                                    newitem["Field_x0020_Type"] = fieldValue2;
                                    newitem["Location"] = fieldValue3;
                                    newitem["User_x0020_ID_x003a_ID"] = fieldValue4;
                                    newitem["Current_x0020_Date"] = fieldValue5;
                                    newitem["New_x0020_Date"] = fieldValue6;
                                    newitem["Alternate_x0020_Date"] = fieldValue7;
                                    newitem["New_x0020_Status"] = fieldValue8;
                                    newitem["First_x0020_Reason"] = fieldValue9;
                                    newitem["Second_x0020_Reason"] = fieldValue10;
                                    newitem["Third_x0020_Reason"] = fieldValue11;
                                    newitem["Finance_x0020_Informed_x0020_of_"] = fieldValue12;
                                    newitem["New_x0020_Notice"] = fieldValue13;
                                    newitem["Associate_x0020_Region"] = fieldValue14;
                                    newitem["Primary_x0020_Reason_x"] = fieldValue15;
                                    newitem["Secondary_x0020_Reason"] = fieldValue16;
                                    newitem["New_x0020_Field_x0020_Type"] = fieldValue17;
                                    newitem.Update();
                                }
                            }
                            web.AllowUnsafeUpdates = false;
                        }
                    }
                }
            }
        }
Also, I do have two nodes on my main data connection that I'm trying to send to the same line on the same list, one being a repeating section, the other a repeating table.  Not sure if this has anything to do with the error. Thanks in advance for any help!

Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>