ok why do I get an error on the writer.Close() method?
The XML files says:
XML document must have a top level element.
But I do..or I thought I do...please help.
The XML files says:
XML document must have a top level element.
But I do..or I thought I do...please help.
Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace StreamingUpload
/* The XmlRootAttribute allows you to set an alternate name
(PurchaseOrder) for the XML element and its namespace. By
default, the XmlSerializer uses the class name. The attribute
also allows you to set the XML namespace for the element. Lastly,
the attribute sets the IsNullable property, which specifies whether
the xsi:null attribute appears if the class instance is set to
a null reference. */
[XmlRootAttribute("ULSettings", Namespace="http://www.coralridge.org", IsNullable = false)]
public class ULSettings
{
public CINFTP CINFTP;
}
public class CINFTP //Old Address Class
{
/* The XmlAttribute instructs the XmlSerializer to serialize the Name
field as an XML attribute instead of an XML element (the default
behavior). */
[XmlAttribute]
public string CINHost;
public string CINPassword;
public string CINTTTPathToFile;
public string CINUserID;
}
private void CreateULSettings(string filename)
{
// Create an instance of the XmlSerializer class;
// specify the type of object to serialize.
XmlSerializer serializer = new XmlSerializer(typeof(ULSettings));
TextWriter writer = new StreamWriter(filename);
CINFTP CINFTP = new CINFTP();
CINFTP.CINHost = "216.25";
CINFTP.CINPassword = "dfsdfsdf";
CINFTP.CINTTTPathToFile = "/TTT/";
CINFTP.CINUserID = "sdfsdf";
// Serialize the purchase order, and close the TextWriter.
serializer.Serialize(writer, CINFTP);
writer.Close();
}
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
CreateULSettings("ULSettings.xml");
Last edited by a moderator: