-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();
DLeh
  • 23,806
  • 16
  • 84
  • 128

1 Answers1

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

George Saad
  • 2,161
  • 1
  • 14
  • 7