Hello guys im having a problem and i dont see where i made error. Im tryting to write something into XML file. Also how do you read textbox input and save it into XML ??
Cheers for help :)
public class CourseName
{
string _name;
public CourseName(string name)
{
this._name = name;
}
public string Name { get { return _name; } }
}
private void button1_Click(object sender, EventArgs e)
{
CourseName[] courseNames = new CourseName[4];
courseNames[0] = new CourseName("blablabla");
using (XmlWriter writer = XmlWriter.Create("myCourses1234.xml"))
{
writer.WriteStartDocument();
writer.WriteStartElement("myCourse");
foreach (CourseName coursename in courseNames)
{
writer.WriteStartElement("myCourse");
writer.WriteElementString("courseName", coursename.Name); //<---- Object reference not set to an instance of an object
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
}
}