Hi I have the following edited application code -
public partial class ConvertApp : Form
{
public ConvertApp()
{
InitializeComponent();
}
static webservice.Results res= new webservice.Results(out int factSent,out int ComSent)
private static webservice.Results convert()
{
string csv = File.ReadAllText("C:\\test.txt");
string year = "1000" ;
XDocument doc = ConvertCsvToXML(csv, new[] { "," });
webservice.Feed CallWebService = new webservice.Feed();
int recordAmount=0;
factSent = 0;
ComSent = 0;
foreach(XElement el in doc.Descendants("row"))
{
recordAmount = recordAmount+1;
}
webservice.Summary[] Summary = new webservice.Summary[recordAmount];
int i=0;
foreach(XElement el in doc.Descendants("row"))
{
Summary[i] = new webservice.Summary();
Summary[i].person = el.Descendants("var").Where(x => (string)x.Attribute("name") == "person").SingleOrDefault().Attribute("value").Value;
Summary[i].fact = System.Convert.ToInt32(el.Descendants("var").Where(x => (string)x.Attribute("name") == "fact").SingleOrDefault().Attribute("value").Value);
Summary[i].com = System.Convert.ToInt32(el.Descendants("var").Where(x => (string)x.Attribute("name") == "com").SingleOrDefault().Attribute("value").Value);
Summary[i].Centre = el.Descendants("var").Where(x => (string)x.Attribute("name") == "Centre").SingleOrDefault().Attribute("value").Value;
Summary[i].CCentre = el.Descendants("var").Where(x => (string)x.Attribute("name") == "CCentre").SingleOrDefault().Attribute("value").Value;
factSent += Summary[i].fact;
ComSent +=Summary[i].com;
i=i+1;
}
webservice.Results res = CallWebService.updateStatus(Summary, year);
return res;
}
private void Form1_Load(object sender, EventArgs e)
{
int factSent;
int ComSent;
webservice.Results returned = convert(out factSent, out ComSent);
txtResult.Text = System.Convert.ToString(returned.status);
txtMoreRes.Text = returned.errorDetails[i].errorDetails;
factSum.Text = System.Convert.ToString(returned.factSum);
comSum.Text = System.Convert.ToString(returned.comSum);
factSumSent.Text = factSent.ToString();
comSumSent.Text = ComSent.ToString();
time.Text = System.Convert.ToString(DateTime.Now.TimeOfDay);
date.Text = System.Convert.ToString(DateTime.Today);
lineFault.Text = System.Convert.ToString(returned.errDetails[i].lineFault);
}
My problem is I used the method of gettng the results to load into a web form for demonstration purposes. However now I want to get the xml response to load into a CSV file and save that file automatically to a specific path, I no longer need the application to be a web form, and not sure of how to do this.
Here is an example of the response XML -
<return>
<factSum>24</factSum>
<comSum>15</comSum>
<errDetails>
<errors>The person [123] is unknown , The
centre [14] is unknown </errors>
<Position>0</Position>
</errDetails>
<status>lineFault</status>
</return>
</ns2:FeedResponse>
</S:Body>
And I want the .CSV file to look something like-
date,time,factSent,ComSent,factSum,comSum,errors,Position,status 26/01/2011,14:00,24,15,24,15,The person[123] is unknown,0,lineFault
I have tried StringBuilder SbCSV but could not get it to work as I was not sure how to alter my existing code to use it.
I also tried using an XLS template using System.Configuration;
and System.Xml.Xsl;
that looked like -
<xsl:template match="//return".
<xsl:value-of select="factsum">
//etc
</xsl:template>
And then took out the - private void Form1_Load(object sender, EventArgs e)
and entered
static void Main(string[] args)
{
string oldXML = ConfigurationSettings.AppSettings["res"];
string xsltLocation = ConfigurationSettings.AppSettings["Path to where xsl template is saved"];
string new CSV = ConfigurationSettings.AppSettings["Path to where I want the new CSV to go"];
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load("Path to where xsl template is saved");
transform.Transform(oldXML, newCSV);
}
This however gave me problems with the public partial class ConvertApp : Form
and also that it was a static void Main
and I think the template was configured incorrectly.
Any help would be GREATLY appreciated and thanks for your time.