Link to home
Start Free TrialLog in
Avatar of xiaominghng
xiaominghng

asked on

Reading xml file from another project

Experts,

I am using following code to write an xml file.

    <Serializable()> Public Class mysettings
        Public TestAs String

        Public Sub SaveXml(ByVal Path As String)
            Dim fStream As System.IO.FileStream
            Dim myFormat As New System.Runtime.Serialization.Formatters.Soap.SoapFormatter
            Try
                fStream = New System.IO.FileStream(Path, IO.FileMode.Create, IO.FileAccess.Write)
                myFormat.Serialize(fStream, Me)
                fStream.Close()
            Catch ex As Exception
                MsgBox("Error saving: " & ex.Message, , "Message")
            Finally
                If Not (fStream Is Nothing) Then fStream.Close()
            End Try
        End Sub

        Public Shared Function LoadXML(ByVal Path As String) As mysettings
            Dim fStream As System.IO.FileStream
            Dim myFormat As New System.Runtime.Serialization.Formatters.Soap.SoapFormatter
            Dim tmp As mysettings
            Try
                fStream = New System.IO.FileStream(Path, IO.FileMode.Open, _
                    IO.FileAccess.Read)
                tmp = CType(myFormat.Deserialize(fStream), mysettings)
            Catch ex As Exception
                MsgBox("Error opening: " & ex.Message, , "Message")
            Finally
                If Not (fStream Is Nothing) Then fStream.Close()
            End Try
            Return tmp

        End Function
    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As New mysettings

        x.test = txtTest.Text
        x.SaveXml(Path & "Test.xml")
End Sub

Then I use following code to read the xml file from another project.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As New mysettings
        x = x.LoadXML(Path & "Test.xml")
        txtTest.text = x.test
End Sub


When reading the xml file, I got error message: “Error Open: Parse Error, no assemble associated with Xml key…

I need read the xml file from another project. How can I do that? Any help will be much appreciated.


ASKER CERTIFIED SOLUTION
Avatar of checoo
checoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial