Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Apertura de Archivos en C# ASP.Net interactuando con base de datos SQL Server

Apertura de Archivos en C# ASP.Net interactuando con base de datos SQL Server

Scheduled Pinned Locked Moved C#
csharpdatabasehtmlasp-netsql-server
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hernan Camilo
    wrote on last edited by
    #1

    Cordial saludo equipo de StackoverRun les escribe Hernán Martínez saludos desde Colombia, agradezco si me pueden colaborar acerca del inconveniente que tengo respecto a la apertura de archivos almacenados en una base de datos SQL server mediante el lenguaje de programación C# ASP.Net:

    El video explicativo de mi requerimiento es el siguiente:
    https://www.youtube.com/watch?v=FGSGit5GjzY&feature=youtu.be

    Y el código es el siguiente

    protected void gvContact5_SelectedIndexChanged(object sender, EventArgs e)
    {
    string IdMov = Convert.ToString(gvContact5.DataKeys[gvContact5.SelectedIndex].Value.ToString());
    string query = "select * from compyrifas where idmov = @IdMov";
    var cmd = new SqlCommand(query, sqlCon5);
    cmd.Parameters.AddWithValue("@IdMov", IdMov);
    var DA5 = new SqlDataAdapter(cmd);
    DataTable dtbl = new DataTable();
    DA5.Fill(dtbl);

            if ((dtbl.Rows.Count == 0) || (dtbl.Rows\[0\]\["doc"\] == DBNull.Value))
            {
                MessageBox.Show("Favor vuelva al formulario de Compras\_y\_rifas e inserte el correspondiente documento en el campo con nombre --Documento\_escaneado-- para subir el documento");
            }
            else
            {
    

    string filenm = dtbl.Rows[0]["realname"].ToString();
    var doc = (byte[])dtbl.Rows[0]["doc"];
    Response.Charset = "";

                 Response.Cache.SetCacheability(HttpCacheability.NoCache);
    

    if (filenm.Trim().EndsWith(".pdf"))
    {
    Response.ContentType = "\".pdf\", \"application/pdf\"";
    Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
    Response.BinaryWrite(doc);
    Response.End();
    }
    else if (filenm.Trim().EndsWith(".HTM") || filenm.Trim().EndsWith(".HTML"))
    {

    Response.ContentType = "\".html\", \"application/html\"";
    Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
    Response.BinaryWrite(doc);
    Response.End();

    }
    else if (filenm.Trim().EndsWith(".TIF"))
    {
    Response.ContentType = "\".tiff\", \"application/tiff\"";
    Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
    Response.BinaryWrite(doc);
    Response.End();
    }
    else if (filenm.Trim().EndsWith(".jpeg") || filenm.Trim().EndsWith(".JPG"))
    {
    Response.ContentType = "\".jpeg\", \"application/jpeg\"";
    Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
    Response.BinaryWrite(doc);
    Response.End();
    }
    else if (filenm.Tri

    B 1 Reply Last reply
    0
    • H Hernan Camilo

      Cordial saludo equipo de StackoverRun les escribe Hernán Martínez saludos desde Colombia, agradezco si me pueden colaborar acerca del inconveniente que tengo respecto a la apertura de archivos almacenados en una base de datos SQL server mediante el lenguaje de programación C# ASP.Net:

      El video explicativo de mi requerimiento es el siguiente:
      https://www.youtube.com/watch?v=FGSGit5GjzY&feature=youtu.be

      Y el código es el siguiente

      protected void gvContact5_SelectedIndexChanged(object sender, EventArgs e)
      {
      string IdMov = Convert.ToString(gvContact5.DataKeys[gvContact5.SelectedIndex].Value.ToString());
      string query = "select * from compyrifas where idmov = @IdMov";
      var cmd = new SqlCommand(query, sqlCon5);
      cmd.Parameters.AddWithValue("@IdMov", IdMov);
      var DA5 = new SqlDataAdapter(cmd);
      DataTable dtbl = new DataTable();
      DA5.Fill(dtbl);

              if ((dtbl.Rows.Count == 0) || (dtbl.Rows\[0\]\["doc"\] == DBNull.Value))
              {
                  MessageBox.Show("Favor vuelva al formulario de Compras\_y\_rifas e inserte el correspondiente documento en el campo con nombre --Documento\_escaneado-- para subir el documento");
              }
              else
              {
      

      string filenm = dtbl.Rows[0]["realname"].ToString();
      var doc = (byte[])dtbl.Rows[0]["doc"];
      Response.Charset = "";

                   Response.Cache.SetCacheability(HttpCacheability.NoCache);
      

      if (filenm.Trim().EndsWith(".pdf"))
      {
      Response.ContentType = "\".pdf\", \"application/pdf\"";
      Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
      Response.BinaryWrite(doc);
      Response.End();
      }
      else if (filenm.Trim().EndsWith(".HTM") || filenm.Trim().EndsWith(".HTML"))
      {

      Response.ContentType = "\".html\", \"application/html\"";
      Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
      Response.BinaryWrite(doc);
      Response.End();

      }
      else if (filenm.Trim().EndsWith(".TIF"))
      {
      Response.ContentType = "\".tiff\", \"application/tiff\"";
      Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
      Response.BinaryWrite(doc);
      Response.End();
      }
      else if (filenm.Trim().EndsWith(".jpeg") || filenm.Trim().EndsWith(".JPG"))
      {
      Response.ContentType = "\".jpeg\", \"application/jpeg\"";
      Response.AddHeader("Content-disposition", "attachment; filename=" + filenm);
      Response.BinaryWrite(doc);
      Response.End();
      }
      else if (filenm.Tri

      B Offline
      B Offline
      BillWoodruff
      wrote on last edited by
      #2

      Please post in English ... use Google translator if necessary.

      «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups