How to migrate TXT file to WebService?

0

Good people

I have this code:

  public static string filePath = Path.GetTempPath();

    public static void ImportFile(string path, string fileToRead)
    {

        if (!File.Exists(path))
            File.Create(path).Close();


        using (XmlTextWriter writer = new XmlTextWriter(path, null))
        {
            string[] lines = System.IO.File.ReadAllLines(fileToRead);
            string cabecalho = lines.Where(x => x.Contains("#")).FirstOrDefault();
            cabecalho = cabecalho.Substring(1);
            string[] headers = cabecalho.Split('|').Select(x => x.Trim().TrimEnd().TrimStart()).ToArray();

            string[] values = lines.Where(x => !x.Contains("#")).ToArray();

            writer.WriteStartDocument();
            writer.Formatting = System.Xml.Formatting.Indented;
            writer.WriteStartElement("bloodonors");

            Array.ForEach(values, (j) =>
            {
                string value = j;
                value = value.Substring(1);
                string[] v = value.Split('|').Select(x => x.Trim().TrimEnd().TrimStart()).ToArray();
                writer.WriteStartElement("donor");
                for (int i = 0; i < headers.Length; i++)
                {
                    writer.WriteElementString(headers[i], v[i]);
                }
                writer.WriteEndElement();
            });

            writer.WriteFullEndElement();
        }
    }

I would like to know how I can migrate the TXT file used to get XML to a webservice?

Greetings

    
asked by anonymous 05.01.2018 / 16:58

0 answers