About Brandon Drake Expertise I can answer questions regarding the Graphics object, file access, general optimization, printing (on paper), user controls, program mathematics, the registry, creating macros, processes, and fundamental or basic questions. I have made a few asp.net pages but I do not know the language extensively. I have not done much work with databases but I have created my own database systems.
Experience I have been programming with visual basic for 6 years. In all I have written programs in about 8 programming languages, although, I only know about 3 well. I have written a few applications but mainly I like to write programs for fun.
Expert: Brandon Drake Date: 7/5/2006 Subject: VB.NET and XML
Question
-------------------------
Followup To
Question -
Hi Brandon,
I'm new to vb.net but am trying to extract data and save it in .xml format, the answer you gave to Ali's question helped me but I was just wondering what to declare the objMyAddresses as?
here is your answer to ali
Dear Ali,
Add a button to the form for the save button. The code for saving the data is very easy. You will want to let the users select a file by using the SaveFileDialog control. Add the SaveFileDialog control to your form to use the code below (I named mine "SaveFileDialog"). In the click event of the button put the code:
SaveFileDialog.Filter = "XML|*.xml"
SaveFileDialog.AddExtension = True
If SaveFileDialog.ShowDialog() = DialogResult.OK Then
objMyAddresses.WriteXml(SaveFileDialog.FileName, XmlWriteMode.WriteSchema)
End If
Some of the lines above may have been wrapped in the email so be careful. Next you will also want an "Open" button to open your database. Add the button and an OpenFileDialog control to allow the user to select the file. Use the following code in the open button's click event:
OpenFileDialog.Filter = "XML|*.xml"
If OpenFileDialog.ShowDialog = DialogResult.OK Then
objMyAddresses.ReadXml(OpenFileDialog.FileName, XmlReadMode.ReadSchema)
End If
The "Filter" property of these codes represents what files will be shown in the dialogs. So in this case only files ending in ".xml" will be shown.
Also, you probably want to add some code to allow the user to save if they close the application on accident without saving.
Yours hopefully,
Amanda
Answer -
Amanda,
The "objMyAddresses" is a DataSet which should be in the toolbox (where the buttons, textboxes, etc. are). You can look that up in help to get more information.
Also, check out the System.XML namespace if you have not. This has a whole lot of xml stuff.
I did a search of the internet and found an example using XML that may be helpful. Here is the URL:
The filter is the code that allows the file dialog to show only xml documents, or word documents etc.
The fields are separated by the Bar character (Shift + Backslash). The filter is set-up in pairs--first you put the text that is shown to the user ("XML Files") and then you put the extension used to filter ("*.xml").
The operating system does not use the first part of each pair to filter the files. For example if you (incorrectly) used the filter "DOC Files|*.xml", you could select "DOC Files" in the Save File Dialog box but only xml files would be shown.