How to save with unique ID
-
Hi all.. I am trying to write to a xml file... The problem i am facing is....I am writing in a for loop.. Each time it is replacing with the old one.. I am trying with the code..
for (int indx = 0; indx < contact.Fields.Count; indx++)
{StreamWriter sw = new StreamWriter(@"D:\\Temp\\File.xml"); sw.WriteLine(contact.Xml); sw.Flush(); sw.Close();
}
what i wanted is change the file name with File1.xml,File2.xml,....etc can anyone help.. thank you manju
Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
-
Hi all.. I am trying to write to a xml file... The problem i am facing is....I am writing in a for loop.. Each time it is replacing with the old one.. I am trying with the code..
for (int indx = 0; indx < contact.Fields.Count; indx++)
{StreamWriter sw = new StreamWriter(@"D:\\Temp\\File.xml"); sw.WriteLine(contact.Xml); sw.Flush(); sw.Close();
}
what i wanted is change the file name with File1.xml,File2.xml,....etc can anyone help.. thank you manju
Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
Depends on whether you want to overwrite the files written from an older for loop. If this is the case, then you can just write the filename as
@"D:\Temp\File.xml"+i
If you don't want to overwrite files at all, then you'd first have to examine all filenames in the directory (viaDirectory.GetFiles()
) and get the highest file id ever assigned, and start the counter from there. regards -
Depends on whether you want to overwrite the files written from an older for loop. If this is the case, then you can just write the filename as
@"D:\Temp\File.xml"+i
If you don't want to overwrite files at all, then you'd first have to examine all filenames in the directory (viaDirectory.GetFiles()
) and get the highest file id ever assigned, and start the counter from there. regards@"D:\Temp\File" + i + ".xml"
is probably more useful. -
Hi all.. I am trying to write to a xml file... The problem i am facing is....I am writing in a for loop.. Each time it is replacing with the old one.. I am trying with the code..
for (int indx = 0; indx < contact.Fields.Count; indx++)
{StreamWriter sw = new StreamWriter(@"D:\\Temp\\File.xml"); sw.WriteLine(contact.Xml); sw.Flush(); sw.Close();
}
what i wanted is change the file name with File1.xml,File2.xml,....etc can anyone help.. thank you manju
Hi.. I am Mnaju.I have Completed my B.E Computers Science.Lokking for a job.I am interested in VC++ manju
Use a GUID for a filename - they're guaranteed to be unique, and therefore aren't susceptible to stopping/restarting the program.
for (int indx = 0; indx < contact.Fields.Count; indx++)
{
string guid = Guid.NewGuid().ToString().Replace("-","").Replace("{","").Replace("}","");
StreamWriter sw = new StreamWriter(string.Format("D:\\Temp\\{0}.xml", guid));
sw.WriteLine(contact.Xml);
sw.Flush();
sw.Close();
}If you don't want to delete the hyphens or curly braces, remove the
Replace()
method calls."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001