Convert Class list to XML file to import in program.

J

Jonas Carlsen

Guest
Okay... i have now been searching the web for about a week and cant seems to get how to make my current list to a XML file that i later can place on my network share so i can import it from there to my program.

Heres my code from my form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Xml.Linq;


namespace HQ_Installer
{
public partial class Form1 : Form
{

public Form1()
{

InitializeComponent();

This part #region ComboBox1 indhold

//Office OfficeList = new Office();
//OfficeList.ReadXml(@"\\HQ\Software\att.xml");
//comboBox1.DataSource = OfficeList;
//comboBox1.DisplayMember = "Program";
//comboBox1.ValueMember = "sti";
//comboBox1.ValueMember = "side";
//OfficeList.Tables[0].DefaultView.Sort = "Program";
//comboBox1.DataSource = OfficeList.Tables[0];

//Oprettelse af OfficeList
var OfficeList = new[] {
new Office {Program = "Office 2007", sti = @"\\HQ\Software\Microsoft\Office\12\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Office\2007\Tekst.html"},
new Office {Program = "Office 2010 (x86)", sti = @"\\HQ\Software\Microsoft\Office\14\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
new Office {Program = "Office 2010 (x64)", sti = @"\\HQ\Software\Microsoft\Office\14\x64\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
new Office {Program = "Office 2013 (x86)", sti = @"\\HQ\Software\Microsoft\Office\15\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
new Office {Program = "Office 2013 (x64)", sti = @"\\HQ\Software\Microsoft\Office\15\x64\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
new Office {Program = "Office 2016 (x86)", sti = @"\\HQ\Software\Microsoft\Office\16\x86\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
new Office {Program = "Office 2016 (x64)", sti = @"\\HQ\Software\Microsoft\Office\16\x64\Suits\setup.exe", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"}
};
comboBox1.DataSource = OfficeList;
comboBox1.DisplayMember = "Program";
comboBox1.ValueMember = "sti";
comboBox1.ValueMember = "side";

#endregion

This part #region comboBow2 indhold

//Oprettelse af ClientList
var ClientList = new[] {
new Client {Program = "Windows Vista (x86)", sti = @"\\HQ\Software\Microsoft\Windows\6.0\Vista\Vista x64 AIO.ISO", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
};
comboBox2.DataSource = ClientList;
comboBox2.DisplayMember = "Program";
comboBox2.ValueMember = "sti";
comboBox2.ValueMember = "side";

#endregion

this part #region comboBox3 indhold

//Oprettelse af ClientList
var ServerList = new[] {
new Server {Program = "Windows Server 2008 R2 (x86)", sti = @"\\HQ\Software\Microsoft\Windows\6.1\Server 2008 R2\en-ru_windows_server_2008_r2_x64_with_update_aio_34in1_x64_v16.02.22_by_adguard.ISO", side = @"\\HQ\Software\Server Software sider\Data Mangler\Tekst.html"},
};
comboBox3.DataSource = ServerList;
comboBox3.DisplayMember = "Program";
comboBox3.ValueMember = "sti";
comboBox3.ValueMember = "side";
#endregion

}

private void Form1_Load(object sender, EventArgs e)
{

}

//private void Load_comboBox1()
//{
//DataSet ds = new DataSet();
//DataTable dt = new DataTable("Office");
//ds.Tables.Add(dt);
//dt.Columns.Add("Program");
//dt.Columns.Add("sti");
//dt.Columns.Add("side");
//foreach (DataColumn dc in dt.Columns)
//{
//dc.ColumnMapping = MappingType.Attribute;
//}
//FileStream myFileStream = new FileStream(@"\\HQ\Software\att.xml", FileMode.Open, FileAccess.Read);
//StreamReader myXmlStream = new StreamReader(myFileStream);
//ds.ReadXml(myXmlStream);
//myFileStream.Close();
//comboBox1.DataSource = ds.Tables[0];
//comboBox1.DataBind();
//}

#region Microsoft Office tab

//Ændring af info i webBrowser1.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Office c = comboBox1.SelectedItem as Office;
if (c != null)
{
string url = c.side;
webBrowser2.Navigate(url);
}

}

//Åbning af software installer.
private void button1_Click(object sender, EventArgs e)
{
Office c = comboBox1.SelectedItem as Office;
if (c != null)
{
string url = c.sti;
Process.Start(url);
Application.Exit();
}

}
#endregion

#region Microsoft Windows tab
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
Client c = comboBox2.SelectedItem as Client;
if (c != null)
{
string url = c.side;
webBrowser3.Navigate(url);

}

}

//Åbning af software installer.
private void button2_Click(object sender, EventArgs e)
{
Client c = comboBox2.SelectedItem as Client;
if (c != null)
{
string url = c.sti;
Process.Start(url);
Application.Exit();
}

}


#endregion

#region Microsoft Windows Server tab
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
Server c = comboBox3.SelectedItem as Server;
if (c != null)
{
string url = c.side;
webBrowser4.Navigate(url);

}
}

private void button3_Click(object sender, EventArgs e)
{
Server c = comboBox3.SelectedItem as Server;
if (c != null)
{
string url = c.sti;
Process.Start(url);
Application.Exit();
}
}

#endregion

#region Update tab

private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{

}


private void button4_Click(object sender, EventArgs e)
{

}
#endregion

}

}



as you can see in my code have i tryed to implement it but whit bad results.

Heres the Classes it has to work with:

Office Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Xml;
using System.IO;
using System.Xml.Linq;

namespace HQ_Installer
{
class Office

{
public string Program { get; set; }
public string sti { get; set; }
public string side { get; set; }


//public XmlReadMode ReadXml(XmlReader reader);
}

}

Client Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HQ_Installer
{
class Client
{
public string Program { get; set; }
public string sti { get; set; }
public string side { get; set; }
}
}

Server Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HQ_Installer
{
class Server
{
public string Program { get; set; }
public string sti { get; set; }
public string side { get; set; }
}
}


and last but not least heres the XML file i have been using to testing:

<?xml version="1.0" encoding="utf-8" ?>
<OfficeList>
<Field Program="Office 2007" sti="\\HQ\Software\Microsoft\Office\12\x86\Suits\setup.exe" side="http://www.google.com"></Field>
</OfficeList>

Is there anyway to make this to work with my XML file?
And hopfely whit all 3 lists in one XML file.

Continue reading...
 
Back
Top