Create txt file and download asp.net

0
    byte[] binaryCertData = Convert.FromBase64String(lstSellosCliente[0].ArchivoCer);
    var objCert = new System.Security.Cryptography.X509Certificates.X509Certificate2(binaryCertData);
    StringBuilder objSB = new StringBuilder();
    objSB.AppendLine("Detalle del certificado" + "");
    objSB.AppendLine("Usuario: " + txtCliente.Text);
    objSB.AppendLine("Contraseña del Sello: " + lstSellosCliente[0].ContraFiel);
    objSB.AppendLine("Contraseña Web: " + lstSellosCliente[0].ContraWeb);
    objSB.AppendLine("Válido desde: " + objCert.NotBefore.ToString());
    objSB.AppendLine("Válido hasta: " + objCert.NotAfter.ToString());

    byte[] byteArray = Encoding.UTF8.GetBytes(objSB.ToString());

    using (var binaryReader = new BinaryReader(new MemoryStream(byteArray)))
    {
          byteArray = binaryReader.ReadBytes(objSB.Length);
    }

    GenerarArchivo(Convert.ToBase64String(byteArray), "text/txt", txtCliente.Text + ".txt");

I have this code that generates a txt file and download it with the details of some stamps

the method to download the file created with the data I need is the following

 public void GenerarArchivo(String archivos,string Contentypes,string nombreArchivo)
    {
        MemoryStream ms = new MemoryStream();
        byte[] archivo = Convert.FromBase64String(archivos);
        ms.Write(archivo, 0, archivo.Length);
        ms.Close();
        HttpContext context = HttpContext.Current;
        context.Response.ContentType = Contentypes;
        context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", nombreArchivo));
        context.Response.Clear();
        context.Response.BinaryWrite(ms.GetBuffer());
        context.Response.Flush();
        context.ApplicationInstance.CompleteRequest();
    }

What this method does is download the created file, download it well but also add data from my page as the scrip, attached image of the generated file, what is in the red box is what I do not want to leave

Does anyone know what to do so that only in my txt file shows the data I want?

    
asked by Edgar 26.06.2018 в 01:26
source

0 answers