public ActionResult ShowXml(string id) { Guid publicKey; if (!Guid.TryParse(id, out publicKey)) return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest); var comprobante = DBContext.Comprobantes.Where(e => e.PublicKey == publicKey).SingleOrDefault(); if (comprobante == null) return HttpNotFound(); var certificado = DBContext.Certificados.Where(e => e.NumSerie == comprobante.NoCertificado).SingleOrDefault(); //System.IO.MemoryStream ms = new System.IO.MemoryStream(); //CFDIXmlTextWriter writer = // new CFDIXmlTextWriter(comprobante, ms, System.Text.Encoding.UTF8); //writer.WriteXml(); //ms.Position = 0; //System.IO.StreamReader reader = new System.IO.StreamReader(ms); //string xml = reader.ReadToEnd(); //reader.Close(); //writer.Close(); //string xml = comprobante.GetXml(); string cadenaOriginal = comprobante.GetCadenaOriginal(); Response.ClearContent(); Response.ContentType = "application/xml"; Response.ContentEncoding = System.Text.Encoding.UTF8; System.IO.MemoryStream ms = new System.IO.MemoryStream(); CFDIXmlTextWriter writer = new CFDIXmlTextWriter(comprobante, /*ms*/Response.OutputStream, System.Text.Encoding.UTF8); writer.WriteXml(); ms.Position = 0; writer.Close(); return File(ms, "text/xml"); }
public string GetXml() { System.IO.MemoryStream ms = new System.IO.MemoryStream(); CFDIXmlTextWriter writer = new CFDIXmlTextWriter(this, ms, System.Text.Encoding.UTF8); writer.WriteXml(); ms.Position = 0; System.IO.StreamReader reader = new System.IO.StreamReader(ms); string xml = reader.ReadToEnd(); reader.Close(); writer.Close(); return xml; }