Click here to Skip to main content
15,919,567 members
Home / Discussions / C#
   

C#

 
QuestionSending data via IP or MAC address - help [modified] Pin
Anthony Mushrow15-Oct-06 2:18
professionalAnthony Mushrow15-Oct-06 2:18 
AnswerRe: Sending data via IP or MAC address - help Pin
Rob Graham15-Oct-06 3:46
Rob Graham15-Oct-06 3:46 
GeneralRe: Sending data via IP or MAC address - help Pin
Anthony Mushrow15-Oct-06 3:53
professionalAnthony Mushrow15-Oct-06 3:53 
GeneralRe: Sending data via IP or MAC address - help Pin
Nader Elshehabi15-Oct-06 6:00
Nader Elshehabi15-Oct-06 6:00 
QuestionSimple Threading headache Pin
XTr1NiTy14-Oct-06 22:00
XTr1NiTy14-Oct-06 22:00 
AnswerRe: Simple Threading headache Pin
Corinna John14-Oct-06 23:43
Corinna John14-Oct-06 23:43 
GeneralRe: Simple Threading headache Pin
XTr1NiTy15-Oct-06 0:08
XTr1NiTy15-Oct-06 0:08 
QuestionProblem ion Creating XML FIles Pin
farhan197614-Oct-06 21:37
farhan197614-Oct-06 21:37 
Hi,

I am trying to use XML file as an config file. The structure of the xml file is quite simple. It needs to have only

5 fields. This file stores information about 3 websites - so ideally structure should be like

<root>
<config>
<website 1="">
<url>test
<delay>23
<username>23
<password>32423



<website 2="">
<url>test
<delay>23
<username>23
<password>32423




I am using following code to create this Xml schema and xml file - but having some trouble (which i don't know WHY -

and I seek your guidence...)

public void create_Config_Table(string service_name, string url, string delay,
string freq, string username, string password)
{
string filename = "config.xml";
FileStream fs;
XmlTextWriter xtw;
XmlTextReader xtr;

string msg = "";

//create the table and then populate it
DataTable ret = new DataTable(service_name);

//Create the DataSet
DataSet ds = new DataSet("AutoMessage");

//first check if config.xml exists or not
//If it already exists then we don't have to recreate the XML schema for it
if( ! File.Exists(filename) )
{


//ret.Columns.Add("Service", Type.GetType("System.String"));
ret.Columns.Add("URL",Type.GetType("System.String"));
ret.Columns.Add("Delay", Type.GetType("System.String"));
ret.Columns.Add("Frequency",Type.GetType("System.String"));
ret.Columns.Add("Username",Type.GetType("System.String"));
ret.Columns.Add("Password",Type.GetType("System.String"));

//Now populate the data table
DataRow row = ret.NewRow();

//row["Service"] = service_name;
row["URL"] = url;
row["Delay"] = delay;
row["Frequency"] = freq;
row["Username"] = username;
row["Password"] = password;

ret.Rows.Add(row);
ds.Tables.Add(ret);

msg = "Config File Created";
}
else
{
//Read the XML File
try
{
fs = new FileStream(filename, FileMode.Open);
xtr = new XmlTextReader(fs);

ds.ReadXml(xtr);
xtr.Close();

DataTable dt = ds.Tables[0];

DataRow row = dt.NewRow();
//row["Service"] = service_name;
row["URL"] = url;
row["Delay"] = delay;
row["Frequency"] = freq;
row["Username"] = username;
row["Password"] = password;

dt.Rows.Add(row);
ds.Tables.Remove(ds.Tables[0].TableName);
ds.Tables.Add(dt);
msg = "Config File Updated";
}
catch(Exception ex) { Console.Error.WriteLine(ex.ToString() ) ; }

fs = null;
}




try
{
fs= new FileStream(filename, FileMode.Append,FileAccess.Write);
xtw = new XmlTextWriter(fs, System.Text.Encoding.Unicode);

ds.WriteXml(xtw);
xtw.Close();
Console.Write(msg);
}
catch(Exception ex) { Console.Error.WriteLine(ex.ToString() ); }
}

Logic here is that if file doesn't exists - it will create the xml schema and the xml file

if it does EXISTS - then it is read into an dataset - new values are appeneded to contents of this dataset it is
written back as a xml file.

- Major problem is that it creates a mal-formed XML (multiple root elements)
-- Any Suggestions

THanx in advance
AnswerRe: Problem ion Creating XML Files Pin
Larantz15-Oct-06 3:06
Larantz15-Oct-06 3:06 
QuestionHow can I list all functions in a Win32 dll? Pin
Igor Lima14-Oct-06 20:50
Igor Lima14-Oct-06 20:50 
AnswerRe: How can I list all functions in a Win32 dll? Pin
Corinna John14-Oct-06 22:36
Corinna John14-Oct-06 22:36 
AnswerRe: How can I list all functions in a Win32 dll? Pin
Dave Kreskowiak15-Oct-06 4:09
mveDave Kreskowiak15-Oct-06 4:09 
Questionmulti dimension array in an attribute Pin
Thomas Guilbault14-Oct-06 20:33
Thomas Guilbault14-Oct-06 20:33 
QuestionGetting info from a Access database Pin
spepperchin14-Oct-06 18:59
spepperchin14-Oct-06 18:59 
QuestionGetting better memory performance Pin
kshet2614-Oct-06 16:40
kshet2614-Oct-06 16:40 
AnswerRe: Getting better memory performance Pin
Nader Elshehabi14-Oct-06 18:02
Nader Elshehabi14-Oct-06 18:02 
AnswerRe: Getting better memory performance Pin
leppie14-Oct-06 19:47
leppie14-Oct-06 19:47 
AnswerRe: Getting better memory performance Pin
Guffa15-Oct-06 1:17
Guffa15-Oct-06 1:17 
GeneralRe: Getting better memory performance Pin
kshet2615-Oct-06 8:00
kshet2615-Oct-06 8:00 
AnswerRe: Getting better memory performance Pin
Guffa15-Oct-06 12:12
Guffa15-Oct-06 12:12 
AnswerRe: Getting better memory performance Pin
Guffa15-Oct-06 14:52
Guffa15-Oct-06 14:52 
AnswerRe: Getting better memory performance Pin
WillemM15-Oct-06 1:22
WillemM15-Oct-06 1:22 
QuestionWMI not working. Did I forget something? Pin
junus14-Oct-06 14:09
junus14-Oct-06 14:09 
AnswerRe: WMI not working. Did I forget something? Pin
Dave Kreskowiak14-Oct-06 19:31
mveDave Kreskowiak14-Oct-06 19:31 
QuestionListView SubItem Rollover Pin
smarttom9914-Oct-06 13:42
smarttom9914-Oct-06 13:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.