Null Object Reference Copy data from sharePoint list. - InfoPath Dev
in

InfoPath Dev

Null Object Reference Copy data from sharePoint list.

Last post 12-28-2012 08:42 AM by Jimmy. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-26-2012 01:28 PM

    Null Object Reference Copy data from sharePoint list.

    I have a SharePoint I am trying to populate a repeating table in the form. I keep  getting a Object reference not set to an instance of an object. on the Elements @Start_Postion, @End_Postion, @ Lenght.

    I am not sure if I am doing something completely wrong or not.

    here is the code i have so far.

    XPathNavigator secDSNav = DataSources["File Layout Container"].CreateNavigator();

    // Retrieve the rows of the secondary data source

    XPathNodeIterator rows = secDSNav.Select(

    "/dfs:myFields/dfs:dataFields/dfs:File_Layout_Container", NamespaceManager);

    // Loop through the rows of the secondary data source and fill the repating table

    while (rows.MoveNext())

    {

    string FieldName = rows.Current.SelectSingleNode(

    "@Field_Name", NamespaceManager).Value;

    string DataType = rows.Current.SelectSingleNode(

    "@Data_Type", NamespaceManager).Value;

    string StartPosition = rows.Current.SelectSingleNode(

    "@Start_Position", NamespaceManager).Value;

    string EndPosition = rows.Current.SelectSingleNode(

    "@End_Position", NamespaceManager).Value;

    string Position = rows.Current.SelectSingleNode(

    "@Positon", NamespaceManager).Value;

    string Length = rows.Current.SelectSingleNode(

    "@Length", NamespaceManager).Value;

    // Add the item to the repeating table

    AddItem(FieldName, DataType, StartPosition, EndPosition, Position, Length);

    }

    // Remove the first empty item from the repeating table

    DeleteFirstEmptyItem();

    }

    }

     

    private void AddItem(string FieldName, string DataType, string StartPosition, string EndPosition, string Position, string Length)

    {

    XmlDocument doc = new XmlDocument();

    XmlNode group = doc.CreateElement("Targeting_Iteration_Recurrence_File_Layout_Fields",

    NamespaceManager.LookupNamespace("my"));

    XmlNode field = doc.CreateElement("Field_Name_Output_Target",

    NamespaceManager.LookupNamespace("my"));XmlNode node = group.AppendChild(field);

    node.InnerText = FieldName;

    field = doc.CreateElement("Data_Type_Output_Target",

    NamespaceManager.LookupNamespace("my"));

    node = group.AppendChild(field);

    node.InnerText = DataType;

    field = doc.CreateElement(
    "Start_Postion_Output_Target",NamespaceManager.LookupNamespace("my"));

    node = group.AppendChild(field);

    node.InnerText = StartPosition;

    field = doc.CreateElement(
    "End_Postion_Output_Target",NamespaceManager.LookupNamespace("my"));

    node = group.AppendChild(field);

    node.InnerText = EndPosition;

    field = doc.CreateElement(
    "Position",NamespaceManager.LookupNamespace("my"));

    node = group.AppendChild(field);

    node.InnerText = Position;

    field = doc.CreateElement(
    "Length_Output_Target",NamespaceManager.LookupNamespace("my"));

    node = group.AppendChild(field);

    node.InnerText = Length;

    doc.AppendChild(group);

    MainDataSource.CreateNavigator().SelectSingleNode(

    "/my:myFields/my:Section_D_Target_Pop_Req/my:Sub-Section_D6_Output_File_Requirements/my:Preset_Frequency_GRP/my:Recurrence_Frequency/my:Preset_Frequency/my:Targeting_REQ/my:Targeting_Iteration_Recurrence_Additional_File_Layout_Fields",

    NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

    }

    Any help would be great!

  • 12-28-2012 08:42 AM In reply to

    Re: Null Object Reference Copy data from sharePoint list.

    Are the Field_Name, Start_Position, etc. attributes direct children of the File_Layout_Container group, or do they belong to another group below that?
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.