I’m working on the MVC Pattern Winforms example project from this website
Program.cs
static void Main()
{
UserView view = new UserView();
view.Visible = false;
UserController controller = new UserController(view, listLoad());
controller.LoadView();
view.ShowDialog();
}
private static IList listLoad()
{
var users = new ArrayList();
users.Add(new User("Vladimir", "Putin", "122", "Government of Russia", User.SexOfPerson.Male));
return users;
}

public void SaveXML()
{
XmlSerializer serializer = new XmlSerializer(_users.GetType());
using (FileStream fileStream = new FileStream(@"C:\test\Users.xml", FileMode.Create))
{
serializer.Serialize(fileStream, _users);
}
}
What is the problem with the above code?
Question 1: How can i add the user values from the controller instead of loading from the program.cs file IList users = new ArrayList(); ?
Question 2: I want to save all the rows of the list into a XML file, what is the best of way do it ??
When you say add the user values from the controller, what exactly do you mean? Could you not have a method called “AddUsers” on the controller to do that? I appreciate that you would have to stop IList _users from being readonly to do so, however…
As for writing to an XML file, I’d say your best best is XML Serialisation. To do this, you’d probably want to do something like the following in the controller: