-3

I have this Windows form, that inside a button I call a API and I get the information requested. This works very well but I am looking for its when I request the data, I would like to be able to export it into a xml file or to a CSV file. There's a way to achieve this?, here yo have my code.

Thanks

proxy.Dashboard pr = new proxy.Dashboard();
pr.APIKeyValue = new proxy.APIKeyHeader(); 
pr.APIKeyValue.Value = "25478-69874-fde44-ertyy";
proxy.ProjectData[] nc = pr.GetAllProjectData();

StringBuilder sb = new StringBuilder();
foreach (proxy.ProjectData som in nc) 
{ 
    sb.AppendLine("\r\n");  
    sb.AppendLine("\r\n" + som.ProjectTitle + " " + som.ProjectID + " " + som.PublishStatus); 
}

label1.Text = sb.ToString();
5
  • 2
    there are tons of resources on how to export to a xml or csv file. google it. Commented Jan 30, 2015 at 20:16
  • Hi, I been trying to look every where but I had to success that's why I posted the question here. Thanks a lot Commented Jan 30, 2015 at 20:17
  • stackoverflow.com/questions/18757097/writing-data-into-csv-file Commented Jan 30, 2015 at 20:18
  • Linq to XML / XMLwritter / xml serialization... good luck Commented Jan 30, 2015 at 20:21
  • Thanks @DLeh I got the answer over there. Thanks a lot! Commented Jan 30, 2015 at 20:25

1 Answer 1

0

If you want to export to XML add "using System.xml" then loop through your data as follow.

using (XmlWriter writer = XmlWriter.Create("GiveNameToYourFile.xml"))
{
    writer.WriteStartDocument();
    writer.WriteStartElement("GiveTagNameToYourDocument");

    foreach (proxy.ProjectData som in nc)
    {
    writer.WriteStartElement("GiveNameToYourElement");

    writer.WriteElementString("ProjectTitle", som.ProjectTitle);
    writer.WriteElementString("ProjectID", som.ProjectID);
    writer.WriteElementString("PublishStatus", som.PublishStatus);

    writer.WriteEndElement();
    }

    writer.WriteEndElement();
    writer.WriteEndDocument();
}

If you want to export to excel go to http://www.codeproject.com/Articles/692121/Csharp-Export-data-to-Excel-using-OpenXML-librarie very useful helps you export your data to excel using OpenXML Library. Hopefully this help you. Good Luck

Sign up to request clarification or add additional context in comments.

1 Comment

You're most welcome. please vote for the answer if it was helpful and useful. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.