I have a console application that outputs the result into a .csv file. The console application calls several web services and outputs several data. The output contain URLs which differentiate one site from another other. The code works fine, but the output is in one big CSV file and it gets divided when it reaches the header then starts writing the data from the new site.
Here you have how the output is now from the CSV file:
ProjectTitle,PublishStatus,Type,NumberOfUsers, URL
Project one,published,Open,1,http://localhost/test1
Project two,expired,Closed,14,http://localhost/test1
ProjectTitle,PublishStatus,Type,NumberOfUsers,URL
Project one V2,expired,Closed,2,http://localhost/test2
Project two V2,Published,Open,3,http://localhost/test2
What I am trying to do its to either output the first set of data (depending on each URL) and then the second set of data in a different tab in Excel, or just create a new file for the new set of data. My code:
public static XmlDocument xml = new XmlDocument();
static void Main(string[] args)
{
xml.Load("config.xml");
test();
}
private static void test()
{
List<string> url = new List<string>();
int count = xml.GetElementsByTagName("url").Count;
for (int i = 0; i < count; ++i)
{
url.Add(xml.GetElementsByTagName("url")[i].InnerText);
Url = url[i];
}
string listFile = "ListOfSites";
string outCsvFile = string.Format(@"C:\\testFile\\{0}.csv", testFile + DateTime.Now.ToString("_yyyyMMdd HHmms"));
using (FileStream fs = new FileStream(outCsvFile, FileMode.Append, FileAccess.Write))
using (StreamWriter file = new StreamWriter(fs))
file.WriteLine("ProjectTitle,PublishStatus,Type,NumberOfSUsers,URL");
foreach(WS.ProjectData proj in pr.Distinct(new ProjectEqualityComparer()))
{
file.WriteLine("{0},\"{1}\",{2},{3},{4}",
proj.ProjectTitle,
proj.PublishStatus,
proj.type,
proj.userIDs.Length.ToString(NumberFormatInfo.InvariantInfo),
url[i].ToString());
}
}