Loading and Saving XML in a Sample Application


The XmlPhoneBook sample application demonstrates how to load and save DataSet s in XML format. The XML can be stored on the local file system or through a stream associated with an IrDAClient . There is a C# and VB version of XmlPhoneBook in the folder \SampleApplications\Chapter8 .

When the XmlPhoneBook application launches, the screen shows a DataGrid and a series of buttons . The DataGrid shows the contents of a DataSet maintained by the application. To set up a brand new DataSet , follow these steps:

  1. Click the New PhoneBook button. The application responds by creating a new DataSet , but there are no records loaded.

  2. Create a random record and insert it into the DataSet by clicking the Add Random button.

  3. After the random record has been inserted into the DataSet , it appears in the DataGrid .

To save a DataSet to an XML file, click the XML File Save button. The application saves the DataSet in XML format to the file \PhoneBook.xml.

To load a previously saved DataSet , click the XML File Load button. The application attempts to populate the DataSet by loading the file \PhoneBook.xml.

XmlPhoneBook can also transmit a populated DataSet by using the infrared port. To do this, follow these steps:

  1. Set up a populated DataSet in one device.

  2. Line up the infrared ports on the devices.

  3. Select the Host checkbox on only one of the devices. Click IR Send on one of the devices and IR Receive on the other.

  4. The XmlPhoneBook application sets up an IrDAClient , as described in Chapter 5. It then acquires a handle to the stream associated with the IrDAClient by calling IrDAClient.GetStream() . Finally, the XML data is written to the stream by one device and read from the stream by the other.

There is neither a way to edit the records, nor to choose values for records to insert, nor to choose the filename for saving the DataSet as XML data. This is to keep the application simple and maintain a focus on loading and saving DataSet s in XML format, rather than creating an exercise in user interface design.



Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net