How to access SharePoint list from InfoPath using visual basic and VSTA - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How to access SharePoint list from InfoPath using visual basic and VSTA

Last post 08-14-2007 08:41 PM by stpowell. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-22-2007 04:17 PM

    How to access SharePoint list from InfoPath using visual basic and VSTA

    Hello Everyone,

    I want to be able to read a SharePoint List and process the date in code.  I am using SharePoint 2007 MOSS.

    I have setup a Secondary Data Connection that accesses the list on the SharePoint Server.  If I setup a Drop-Drown List Box to point to the Data Connection I can see the list in the drop down box.

     

    I looked used the help in VSTA and found that I could defend a variable ad as SharepointListQueryConnection

    Dim myQueryConnection As SharepointListQueryConnection = DirectCast(DataConnections("Quoting Tool List"), SharepointListQueryConnection)

     

    The problem is that I can’t find any information on how to use this variable to query the list and give me the results.  Ideally I would put the results in to an array.

     

    Please Help

    Steve

  • 07-15-2007 06:38 PM In reply to

    Re: How to access SharePoint list from InfoPath using visual basic and VSTA

    I still need help with this problem.  I have not had any replies to this issue.  Doesn’t anyone know how to read a SharePoint list using VB code from InfoPath 2007?  I know how to read a repeating table so I creating a secondary data source and drag the secondary data source to the form and created a repeating table.  When I preview the form; all the data from the SharePoint list is seen in the table.  I then tried reading this repeating table which didn’t work.  Maybe you can only read repeating table that are located in the Main data source.

    I really need help figuring this our.  Please can someone help me figure out how to read data from a SharePoint list?  This list will be part of my Secondary Data source if that helps.

    My code to read a repeating table from the Main data source is as follows:

    MessageBox.Show(ReadFieldValue(“/my:myFields/my:repeatingtable[X]/my:City”))

    ‘ Note: [X] is the row I want to read

    Private Function ReadFieldValue(ByVal xpath As String) As String

       Dim root As Xml.XPath.XPathNavigator = Me.MainDataSource().CreateNavigator()

       Dim field As Xml.XPath.XPathNavigator = root.SelectSingleNode(xpath, Me.NamespaceManager())

       Return field.Value

    End Function

    This code will not work when the “xpath” is the path to the Secondary Data source.

     Thank you,

    Steve

  • 08-14-2007 09:11 AM In reply to

    Re: How to access SharePoint list from InfoPath using visual basic and VSTA

    Hi - I am a REAL beginner at this but your snippet of code has just helped me do something I wanted to do.... I can also get access to data in a secondary data source - by doing something like this.

    Dim dsc As DataSourceCollection = Me.DataSources
    Dim secdsc As DataSource = dsc.Item("SecondaryDataSourceName")
    Dim secfield As XPathNavigator
    Dim secnav As XPathNavigator
    secnav = secdsc.CreateNavigator()
    secfield = secnav.SelectSingleNode("xpath_of_field
    ", NamespaceManager)

    Catharine

  • 08-14-2007 08:40 PM In reply to

    Re: How to access SharePoint list from InfoPath using visual basic and VSTA

    I figure out how to access a SharePoint list.  I have several procedures and functions.

    Basically what I am doing is reading a SharePoint list to get data to populate a dropdown list.  The dropdown list points to a repeating table that is populated if there is a match in the primary and secondary fields of the list.

    I hope this helps someone.

            Public Sub AddTempData(ByVal xSDconnectionName As String, ByVal xSDpath As String, ByVal xValueToFind As String, ByVal xCategoryType As String)

                ' This procedure will read secondary data and find all matches.

                ' I searches a primary field and if a match it will search a secondary field for a match

                ' To get the value of the secondary field it will call the GetValueOfSecondaryData function.

                ' When yhere is a match of both primary and secondary fileds it will read values from two other fields

                ' write them to another repeating table.  This table is used for a dropdown list.

                ' When calling this procedure you must pass the:

                '     1.  Secondary Data connection name.  This is the name that you used from the

                '         Tools/Data Connection menu.

                '     2.  Sencodary Data Path

                '     3.  The value to find; this is the value to match in the secondary field

                '     4.  The Category Type; this is the value to match in the primary field

                ' AddTempData("PriceList", "/dfs:myFields/dfs:dataFields/dfs:PriceList/@Category", "T1", "MRC")

                ' NOTE:  the secondary data must use dfs: in stead of my: as you would in the main data section.

                ' NOTE:  the field name but us the @ signe follwoed by the name of the field.

     

                Dim rowNumber As Integer = 0  ' The row number of the Temp Data Repeating Table

                Dim currentRow As Integer = 0  ' The current row that is being read

     

                'Clear out Old data

                Dim rowCount As Integer

                Dim i As Integer

     

                rowCount = GetRowCount("/my:QuotingToolFields/my:Wizard/my:TempData/my:DataTable")

                If rowCount > 1 Then

                    For i = 1 To (rowCount - 1)

                        DeleteRow("/my:QuotingToolFields/my:Wizard/my:TempData/my:DataTable", "/my:QuotingToolFields/my:Wizard/my:TempData")

                    Next

                End If

                rowCount = 0

     

                'Get navigator to the root of the secondary datasource.

                Dim secondaryDataSource As DataSource = DataSources.Item(xSDconnectionName)

                Dim secondaryDOMNavigator As XPathNavigator = secondaryDataSource.CreateNavigator

     

                'Get all the list items from the secondary datasource.

                Dim secondaryListItems As XPathNodeIterator = secondaryDOMNavigator.Select(xSDpath, NamespaceManager)

                Do While secondaryListItems.MoveNext()

                    If secondaryListItems.Current.Value = xValueToFind Then

                        If GetValueOfSecondaryData("PriceList", "/dfs:myFields/dfs:dataFields/dfs:PriceList[" & secondaryListItems.CurrentPosition & "]/@ChargeCategory") = xCategoryType Then

                            rowNumber = rowNumber + 1

                            If rowNumber > 1 Then

                                AddRow("/my:QuotingToolFields/my:Wizard/my:TempData/my:DataTable", "/my:QuotingToolFields/my:Wizard/my:TempData")

                            End If

                            SetFieldValue(GetValueOfSecondaryData("PriceList", "/dfs:myFields/dfs:dataFields/dfs:PriceList[" & secondaryListItems.CurrentPosition & "]/@ID"), "/my:QuotingToolFields/my:Wizard/my:TempData/my:DataTable[" & rowNumber & "]/my:DataID")

                            SetFieldValue(GetValueOfSecondaryData("PriceList", "/dfs:myFields/dfs:dataFields/dfs:PriceList[" & secondaryListItems.CurrentPosition & "]/@Item"), "/my:QuotingToolFields/my:Wizard/my:TempData/my:DataTable[" & rowNumber & "]/my:DataItem")

                        End If

                    End If

     

                Loop

            End Sub

     

            Public Function GetValueOfSecondaryData(ByVal xSDconnectionName As String, ByVal xSDpath As String) As String

                ' This function will return the data for the row and field that is passwed to it.

                ' When calling this procedure you must pass the:

                '     1.  Secondary Data connection name.  This is the name that you used from the

                '         Tools/Data Connection menu.

                '     2.  Sencodary Data Path

                ' GetValueOfSecondaryData("PriceList", "/dfs:myFields/dfs:dataFields/dfs:PriceList[32]/@ChargeCategory")

                ' GetValueOfSecondaryData("PriceList", "/dfs:myFields/dfs:dataFields/dfs:PriceList[" & secondaryListItems.CurrentPosition & "]/@ChargeCategory")

     

                'Get navigator to the root of the secondary datasource.

                Dim secondaryDataSource As DataSource = DataSources.Item(xSDconnectionName)

                Dim secondaryDOMNavigator As XPathNavigator = secondaryDataSource.CreateNavigator

     

                'Get all the list items from the secondary datasource.

                Dim secondaryListItems As XPathNodeIterator = secondaryDOMNavigator.Select(xSDpath, NamespaceManager)

                secondaryListItems.MoveNext() ' need to get to the current node

                Return secondaryListItems.Current.Value

            End Function

     

            Public Sub AddRow(ByVal xpathTable As String, ByVal xpathParent As String)

                ' This procedure will add a row to the end of a repeating table.

                ' When calling this procedure you must pass it the path to the table and the

                ' the path to the oarrent section of the table.

                ' AddRow("/my:myFields/my:TempData/my:Data2", "/my:myFields/my:TempData")

                ' NOTE:  There may be an issue that the repeating table must be in it's own section.

                '        and there can NOT be any other section at the same level as the repeating

                '        table section

     

                Dim row As Xml.XPath.XPathNavigator = Me.MainDataSource.CreateNavigator.SelectSingleNode(xpathTable, NamespaceManager)

                Dim parent As Xml.XPath.XPathNavigator = Me.MainDataSource.CreateNavigator.SelectSingleNode(xpathParent, NamespaceManager)

     

                parent.AppendChild(row)

     

            End Sub

     

            Public Sub DeleteRow(ByVal xpathTable As String, ByVal xpathParent As String)

                ' This procedure will delete the last row in a repeating table.

                ' When calling this procedure you must pass it the path to the table and the

                ' the path to the oarrent section of the table.

                ' DeleteRow("/my:myFields/my:TempData/my:Data2", "/my:myFields/my:TempData")

                ' NOTE:  There may be an issue that the repeating table must be in it's own section.

                '        and there can NOT be any other section at the same level as the repeating

                '        table section

     

                Dim row As Xml.XPath.XPathNavigator = Me.MainDataSource.CreateNavigator.SelectSingleNode(xpathTable, NamespaceManager)

                Dim parent As Xml.XPath.XPathNavigator = Me.MainDataSource.CreateNavigator.SelectSingleNode(xpathParent, NamespaceManager)

     

                parent.MoveTo(row)

                parent.DeleteRange(row)

            End Sub

     

            Public Sub SetFieldValue(ByVal Value As String, ByVal xpath As String)

                ' This procedure allows you to det the value of a Data source.

                ' When calling this procedure you must pass it the value (to be set) and location of the data source.

                ' SetFieldValue("XXX", "my:QuotingToolFields/my:Offices/my:OfficeInfo/my:OfficeName")

                ' or you can read a spcific row in a repeating table:

                ' SetFieldValue("XXX", "my:QuotingToolFields/my:Offices/my:OfficeInfo[32]/my:OfficeName")

                ' or you can use a verable for the row:

                ' SetFieldValue("XXX", "my:QuotingToolFields/my:Offices/my:OfficeInfo[" & CurrentOffice & "]/my:OfficeName")

     

                Dim root As Xml.XPath.XPathNavigator = Me.MainDataSource().CreateNavigator()

                Dim field As Xml.XPath.XPathNavigator = root.SelectSingleNode(xpath, Me.NamespaceManager())

     

                field.SetValue(Value)

     

            End Sub

     

     

  • 08-14-2007 08:41 PM In reply to

    Re: How to access SharePoint list from InfoPath using visual basic and VSTA

    I need to delete this entry

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.