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. Web Development
  3. ASP.NET
  4. displaying image in website from a table field which contains image url

displaying image in website from a table field which contains image url

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasecssasp-netsysadmin
4 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.
  • M Offline
    M Offline
    mavii
    wrote on last edited by
    #1

    hi i am designing a desktop application and a website. i have write the following code in desktop application but facing difficulty to do the same task in website.i am using grid to display data. in desktop application the Event "GridView1_CellClick" exist but in website i dont find it, can anyone tell me what changes to do with the follwing code to apply it in website searchgrid.CurrentRow.Cells[0].Value; Image1.Image = Image.FromFile(path); protected void Page_Load(object sender, EventArgs e) { String strConnection; strConnection = "server=localhost;User ID=sa;Password=sasa;database=rescue15"; SqlConnection conn = new SqlConnection(strConnection); conn.Open(); string s = " SELECT cr_pic FROM criminal WHERE cr_id = " + searchgrid.CurrentRow.Cells[0].Value; SqlCommand com1 = new SqlCommand(s, conn); SqlDataReader dr1 = com1.ExecuteReader(); if (dr1.Read()) { string path = dr1.GetValue(0).ToString(); Image1.Image = Image.FromFile(path); } dr1.Close(); } } i am using ASP.Net with C# and SQL Server2005

    C 1 Reply Last reply
    0
    • M mavii

      hi i am designing a desktop application and a website. i have write the following code in desktop application but facing difficulty to do the same task in website.i am using grid to display data. in desktop application the Event "GridView1_CellClick" exist but in website i dont find it, can anyone tell me what changes to do with the follwing code to apply it in website searchgrid.CurrentRow.Cells[0].Value; Image1.Image = Image.FromFile(path); protected void Page_Load(object sender, EventArgs e) { String strConnection; strConnection = "server=localhost;User ID=sa;Password=sasa;database=rescue15"; SqlConnection conn = new SqlConnection(strConnection); conn.Open(); string s = " SELECT cr_pic FROM criminal WHERE cr_id = " + searchgrid.CurrentRow.Cells[0].Value; SqlCommand com1 = new SqlCommand(s, conn); SqlDataReader dr1 = com1.ExecuteReader(); if (dr1.Read()) { string path = dr1.GetValue(0).ToString(); Image1.Image = Image.FromFile(path); } dr1.Close(); } } i am using ASP.Net with C# and SQL Server2005

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      mavii wrote:

      Image1.Image = Image.FromFile(path);

      This is a waste of time, it creates an image on the server. Generate an img tag which has a src attribute with the server path ( so not the file path, but the path as a URL that a browser can see )

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      M 1 Reply Last reply
      0
      • C Christian Graus

        mavii wrote:

        Image1.Image = Image.FromFile(path);

        This is a waste of time, it creates an image on the server. Generate an img tag which has a src attribute with the server path ( so not the file path, but the path as a URL that a browser can see )

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        M Offline
        M Offline
        mavii
        wrote on last edited by
        #3

        actually i want to display the image of person according to his ID in the table, so in table i have saved the url, as i have used grid, when one clicks on the Grid, the ID in the first column of the grid is picked and image URL of that ID is taken from table which is diplayed in the picturebox.and i hv not any clear idea of server path, will u plz explain it?

        C 1 Reply Last reply
        0
        • M mavii

          actually i want to display the image of person according to his ID in the table, so in table i have saved the url, as i have used grid, when one clicks on the Grid, the ID in the first column of the grid is picked and image URL of that ID is taken from table which is diplayed in the picturebox.and i hv not any clear idea of server path, will u plz explain it?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          If your ASP.NET app can see the file, then it must be within the web application. Sending c:\inetpub\MyApp\images\cgraus.jpg means nothing to the client. \images\cgraus/jpg will work fine, it's a path from the web root.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          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