4 Replies Latest reply on Jan 4, 2018 11:40 AM by Rajendra Vedaraju

    Reading xml file with add-in

    Rajendra Vedaraju

      Hello there,

      I want to add an xml file to the Add-in files list along with my dll. So that I can read some data from the xml file. But how do I read that xml file? How do I get the path of the xml file?

      Thanks in advance.

        • Re: Reading xml file with add-in
          Matthew Cempa

          If you want to include a specific XML file just add it to the project (and set the property copy to output directory to copy always)

          you can find where your assembly is running from by getting it from the assembly like this:

           

          Dim thisAssembly As Assembly
          Public installDir As String
          ThisAssembly.GetAssembly(Me.GetType())
          installDir = System.IO.Path.GetDirectoryName(thisAssembly.Location)
          

           

          You can use System.XmlL and System.Xml.Linq library commands to read the file.

          • Re: Reading xml file with add-in
            Christian Chu

            Check this out

            or you can google it out - there is nothing to do with SW API

            • Re: Reading xml file with add-in
              Jacob Corder

              you can easily convert an xml file to a dataset.

               

              Function GetDatasetFromXML(ByVal XMLFileName As String) As DataSet

                      Dim RetDs As DataSet = Nothing

                      If Len(Trim(XMLFileName)) > 0 Then

                          If My.Computer.FileSystem.FileExists(XMLFileName) = True Then

                              RetDs = New DataSet

                              Dim ConstEnforced As Boolean = RetDs.EnforceConstraints

                              RetDs.EnforceConstraints = False

                              RetDs.ReadXml(XMLFileName, XmlReadMode.ReadSchema)

                              If IsNothing(RetDs) = False AndAlso RetDs.Tables.Count = 0 Then

                                  RetDs.Dispose()

                                  RetDs = Nothing

                              End If

                              If IsNothing(RetDs) = False Then

                                  RetDs.EnforceConstraints = ConstEnforced

                              End If

                          End If

                      End If

                      Return RetDs

                  End Function