OpenFileDialog messing up XmlSerializer

  • Thread starter Thread starter Matthew
  • Start date Start date
M

Matthew

The code is here:

http://www.osbornewood.com/matthew/vb.cfm



I am trying to Serialize soundFile.Text to an XML file. I have two buttons:
Browse and Save Settings. You can enter a value the textbox and click Save
Settings and it will generate a file settings.xml. The contents of
soundFile.Text are in that file.

You can change the value of soundFile.Text and click Save Settings and it
will regenerate the XML file.

Here is the strange part. Click Browse, choose any file, and click OK.

Change the value of soundFile.Text and click Save Settings. It will not
regenerate the XML file!

Does anybody have any clue what's going on?



Matthew
 
I figured it out.
I was using a relative path to the XML file.
Example:
Dim fs As FileStream = New FileStream("settings.xml", FileMode.Create)

When I choose a file with the OpenFileDialog, it changed the current path to
the directory where the other file is stored.
It was generating the XML file after all, but saving it to my sound files
directory instead of my program directory.

I created a global variable with the full path:
Dim myXmlFile As String = Path.GetFullPath("settings.xml")

And I used that variable in my code:
Dim fs As FileStream = New FileStream(myXmlFile, FileMode.Create)

No more problems.

Matthew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top