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. image name

image name

Scheduled Pinned Locked Moved ASP.NET
question
3 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
    Marix
    wrote on last edited by
    #1

    In my web project I need to show pictures using datalist. So when I set image source to let's say src='GetPicture.aspx?id=[id]' everything works fine, but when someone wants to save that picture it being saved as GetPicture.aspx, so user has to manually rename it afterwards to something.jpg. Is there a way to tell image name and extension? Thank you

    M 1 Reply Last reply
    0
    • M Marix

      In my web project I need to show pictures using datalist. So when I set image source to let's say src='GetPicture.aspx?id=[id]' everything works fine, but when someone wants to save that picture it being saved as GetPicture.aspx, so user has to manually rename it afterwards to something.jpg. Is there a way to tell image name and extension? Thank you

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, You simply use the filename parameter of the Content-Disposition header field to suggest a filename for the image. The sample code in the GetPicture.aspx is simple like this:

      private void Page_Load(object sender, System.EventArgs e)
      {
      Response.Clear();

          byte\[\] bytes = GetImageContent();
                         
          Response.AddHeader("Content-Disposition", "filename=myphoto.jpg");
          Response.OutputStream.Write(bytes, 0, bytes.Length);
          Response.End();
      

      }

      When you right click on the image and select Save Picture As..., the filename myphoto.jpg will appear in the Save Picture dialog box. For more information, see Content-Disposition header field[^].

      M 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, You simply use the filename parameter of the Content-Disposition header field to suggest a filename for the image. The sample code in the GetPicture.aspx is simple like this:

        private void Page_Load(object sender, System.EventArgs e)
        {
        Response.Clear();

            byte\[\] bytes = GetImageContent();
                           
            Response.AddHeader("Content-Disposition", "filename=myphoto.jpg");
            Response.OutputStream.Write(bytes, 0, bytes.Length);
            Response.End();
        

        }

        When you right click on the image and select Save Picture As..., the filename myphoto.jpg will appear in the Save Picture dialog box. For more information, see Content-Disposition header field[^].

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

        thanx a lot!

        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