Error tring to extract a hyperlink from a file. - InfoPath Dev
in

InfoPath Dev

Error tring to extract a hyperlink from a file.

Last post 01-20-2012 10:13 AM by robee31. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-19-2012 06:06 PM

    Error tring to extract a hyperlink from a file.

    It has been a long day and this code is giving me this error.

    System.NullReferenceException
    Object reference not set to an instance of an object.
       at DPR_Library_5.FormCode.CTRL177_5_Clicked(Object sender, ClickedEventArgs e) in \\srv-na01\user\rep\InfoPath Projects\DPR_Library_Final_1_GetFile\FormCode.vb:line 76
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

     

     Public Sub CTRL177_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)       

     

                Dim openFileDialog1 As New OpenFileDialog()

                openFileDialog1.InitialDirectory = "G:\"

     

                openFileDialog1.Filter = "All files (*.*)|*.*"

     

                openFileDialog1.FilterIndex = 2

     

                openFileDialog1.RestoreDirectory = True

     

                If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then

                    Dim uri As New Uri(openFileDialog1.FileName)

     

                    Dim first As XPathNavigator = MainDataSource.CreateNavigator(). _

                    SelectSingleNode("/my:myFields/my:DPR_Library_5/my:group4/my:artworkLocation", NamespaceManager)

     

                    If first.Value Is "" Then

     

                        MainDataSource.CreateNavigator(). _

                        SelectSingleNode("/my:myFields/my:DPR_Library_5/my:group4/my:artworkLocation", NamespaceManager). _

                        SetValue(uri.OriginalString)

                    Else

                        Dim myNamespace As String = NamespaceManager.LookupNamespace("my")

     

                        Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _

                       "/my:myFields/my:DPR_Library_5", NamespaceManager).AppendChild()

                            writer.WriteStartElement("group4", myNamespace)

                            writer.WriteElementString("artworkLocation", myNamespace, uri.OriginalString)

                            writer.WriteEndElement()

                            writer.Close()

     

                        End Using

     

                    End If

     

                End If

            End Sub

     

  • 01-20-2012 08:39 AM In reply to

    Re: Error tring to extract a hyperlink from a file.

    Which line is line 76?

    My suspect would be this line:

     If first.Value Is "" Then

    Because if the variable "first" is NULL, it would throw this error when you tried to get it's value.

    Do you know how to run your code in debug? (I don't mean that question to be patronizing, just sometimes we see that - here's a blog post to help if you don't know how.) That can help you track down the error.

    Hilary Stoupa

  • 01-20-2012 10:13 AM In reply to

    Re: Error tring to extract a hyperlink from a file.

    I know how to run it in in debug I had been up for 15 hours and exhausted, I did not see the line 76 on my screen as I was remotely connected until I posted.

    I changed my code and fixed the error.

    Thanks for the reply.

              

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