C # How to convert string to System.IO.StreamWriter?

3

Hi, I have the following problem, I want to write my csv but I put the accents wrong with strange characters. Then I want to add UTF8 but when I put it on, more Encoding.UTF8 already tells me that

  

Unable to convert string to System.IO.Stream

    using (System.IO.StreamWriter escritor = new System.IO.StreamWriter(@"C:\Users\NUEVO\Desktop\xd\mylittlepony.csv", Encoding.UTF8))

                    {
                        escritor.WriteLine("Nombre,Email,Compania,Web,Direccion,Telefono,Giro");
                    }

If I put this part without Encoding.UTF8 in this part it works but with strange characters.

using (System.IO.StreamWriter escritor = new System.IO.StreamWriter(@"C:\Users\NUEVO\Desktop\xd\mylittlepony.csv"))

Thank you.

    
asked by laur 10.08.2018 в 17:39
source

1 answer

4

You are using the overload badly, 3 parameters are required for that case

new System.IO.StreamWriter(@"C:\Users\NUEVO\Desktop\xd\mylittlepony.csv", false, Encoding.UTF8)

The Boolean indicates whether you want the file to be over (false) or if you want it to add the content to the existing one (true)

    
answered by 10.08.2018 / 17:46
source