public static void EscribreArchivoCSV(String ruta, List <String> Titulos, List <List <Object> > Informacion) { if (Titulos.Count != 0 && Informacion.FirstOrDefault().Count != 0) { if (Titulos.Count == Informacion.FirstOrDefault().Count) { using (var Stream = new StreamWriter(ruta, false, System.Text.Encoding.GetEncoding(1252))) { System.Text.StringBuilder Textos = new System.Text.StringBuilder(); Textos.AppendLine(String.Join(",", Titulos)); foreach (var Linea in Informacion) { List <String> LineaFormato = new List <String>(); var lstString = Linea.OfType <String>(); foreach (var Elemento in lstString) { var Item = Elemento; if (Item.Contains(Environment.NewLine)) { Item = Item.Replace(Environment.NewLine, " "); } if (Item.Contains(@"""")) { Item = Item.Replace(@"""", @""""""); } if (Item.Contains(",")) { Item = @"""" + Item + @""""; } LineaFormato.Add(Item); } Textos.AppendLine(String.Join(",", LineaFormato)); } Stream.Write(Textos.ToString()); } } } }