locked
Loading Picture or Image from file using c# on a Web Form RRS feed

  • Question

  • User-1757935082 posted
    Hi I'm trying to load a picture or image from file and have the image shown on my web form.  I have two problems with this.  One, I dont see the PictureBox control in my tool list, only the image control.

    Second problem, I tried to load an image from file and got an error about object not created. Does this mean that I have to first do something like this in C# before I write the load FromFile method?

    image = new image();

    Do I have to have this line in my code?

    Thanks for any ideas,


    AlexanderBlade
    Friday, August 26, 2005 3:47 PM

All replies

  • User822964765 posted
    you can use page to drow your image by using Response.BinaryWrite method

    System.IO.FileStream FS = System.IO.File.Open("Image Path",System.IO.FileMode.Open);
    byte[] bytes = new byte[FS.Length];
    FS.Read(bytes, 0, bytes.Length);
    FS.Close();
    Response.BinaryWrite(bytes);


    you can put this image any where in other pages by using html image control
    <img scr="path of page that containing code">

    i hope this help
    Friday, August 26, 2005 10:06 PM
  • User1073496067 posted
    <asp:Image id="Image1" AlternateText="Image Text" ImageUrl="images/image1.jpg" runat="server" />
    hope it help
    Saturday, August 27, 2005 4:43 AM
  • User-935300950 posted

    System.IO.FileStream FS = System.IO.File.Open("Image Path",System.IO.FileMode.Open);
    byte[] bytes = new byte[FS.Length];
    FS.Read(bytes, 0, bytes.Length);
    FS.Close();
    Response.BinaryWrite(bytes);


    you can put this image any where in other pages by using html image control
    <img scr="path of page that containing code">

    Sorry for bringing up an old thread but I just wanted to say this (Ahmed Abu Daqqa's answer above) worked perfectly for me. It allowed me to display an image from a different hard drive than the one my IIS web service is on. Also I posted without quoting sorry.

    Wednesday, June 9, 2021 10:13 PM