Image Web Form Control Problem

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: Image Web Form Control Problem

    What you need to do is to create an ASPX Page that generates the image. It
    should set the Response.ContentType property to "imgae/jpg" and then save
    the image the Response.OutputStream. Then your image tag can reference that
    ASPX page instead of a file with an image in it.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    [url]http://www.takempis.com[/url]
    Complex things are made up of
    lots of simple things.

    "Gary B" <deanblakely@earthlink.net> wrote in message
    news:e7HzmPFWDHA.888@TK2MSFTNGP10.phx.gbl...
    > I have an asp.net application that retrieves a bitmap from my Sql Server
    > database and I an trying to put it into a web form image control.
    > Unfortunitely an image web form control won't handle a .net image type and
    > will only accept an image from a file set by the imageURL property.
    >
    > My tactic is to drag the image out of the sql server database, save it to
    a
    > file on my web server, and then set the imageURL property to that saved
    > file. Seemed like a good approach.
    >
    > For reasons beyond the scope of this issue, I am saving it as
    > C:\curentpic.jpg with the following code:
    >
    >
    > FilePath = "C:\currentpic.jpg"
    > myImage.Save(FilePath, Imaging.ImageFormat.Jpeg)
    > myImageCtrl.ImageUrl = FilePath
    >
    > This works fine on my dev box. But when I run the page using i.e. from
    > another computer it looks for the picture in c:\ on that computer!!
    >
    > the code generated to the browser is as follows:
    > </select><img id="DBAPictureBox1" src="C:\currentpic.jpg" border="0"
    > style="height:90px;width:120px;Z-INDEX: 106; LEFT: 480px; POSITION:
    > absolute; TOP: 192px" /><span id="MsgBox"
    style="color:Red;font-family:Times
    > New Roman;font-weight:bold;width:512px;Z-INDEX: 107; LEFT: 96px; POSITION:
    > absolute; TOP: 16px"></span>
    >
    > As can be seen, src is set to c:\currentpic.jpg.
    >
    > It seems, from all of this, that the notion of seting the imageURL
    property
    > to a file is bogus. Does anyone know how can I stream this binary image
    > from my database into a real URL?
    >
    >
    > (BTW, I realize C:\ is a bad place to put the .jpg and Steve Orr showed be
    a
    > way to save it to c:\inetpub\wwwroot\myproject\mycurrentpic.jpg but that
    > save won't even work on my dev box as it gets a GDI + exception but this
    is
    > really another problem)
    >
    > Thanks,
    > Gary
    >
    >

    Kevin Spencer Guest

  2. Similar Questions and Discussions

    1. problem with image url browser button inside control colection designer?!??
      I have this situation: 1) server CustomControl MyControl inherited from WebControl 2) child controls collection is of inherited ImageButton type...
    2. Open Image in 'Kodak Image Edit Control' with web browser.
      hi, 1.I want to show a image file of type '.tif' in the browser window; for that I'm writting as ASP code page. 2.This '.tif' type image can be...
    3. ListView + GT Image control in form: Could somebody take a look what I am doing wrong?
      Hi, All! I have some problem with using GT Image in my MS Access 2000/XP form. I can't find answer within http://www.gtactive.com . Forum...
    4. Problem with Date & Time Picker control in a Tab Control form
      I'm using the DTPicker (Date and Time Picker) ActiveX control within an ACC2000 Tab Control subform contained within a main form. As I scroll...
    5. Master Form with tab control sort problem
      I am using a master form with tab controls. The master form is the property and the tabs all have information related to that property. The subform...
  3. #2

    Default Re: Image Web Form Control Problem

    It's called ImageURL, not ImagePath.
    You need to give it a real URL, as in [url]http://www.mysite.com/myproject/myimage.aspx[/url]
    Then the myimage.aspx page should return nothing but the image.
    The page should also have the appropriate Response.ContentType set.
    Then you can reference reference your image page with a standard Image tag or Image control
    from your main page. <img src='myimage.aspx' ...>

    Assuming you are reading the image out of a database, the code would look something like this:

    Dim dr As System.Data.SqlClient.SqlDataReader


    Response.Clear

    cmdGetFile.Parameters("@File_ID").Value = Request("ImageID").ToString

    dbConn.Open()

    dr = cmdGetFile.ExecuteReader


    If dr.Read Then

    Response.ContentType = dr("ContentType").ToString

    Response.OutputStream.Write(CType(dr("FileData"), Byte()), 0, CInt(dr("FileSize")))

    Else

    Response.Write("File Not Found.")

    End If



    Here's more info:

    [url]http://www.aspnetpro.com/features/2003/07/asp200307so_f/asp200307so_f.asp[/url]



    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]





    "Gary B" <deanblakely@earthlink.net> wrote in message news:e7HzmPFWDHA.888@TK2MSFTNGP10.phx.gbl...
    > I have an asp.net application that retrieves a bitmap from my Sql Server
    > database and I an trying to put it into a web form image control.
    > Unfortunitely an image web form control won't handle a .net image type and
    > will only accept an image from a file set by the imageURL property.
    >
    > My tactic is to drag the image out of the sql server database, save it to a
    > file on my web server, and then set the imageURL property to that saved
    > file. Seemed like a good approach.
    >
    > For reasons beyond the scope of this issue, I am saving it as
    > C:\curentpic.jpg with the following code:
    >
    >
    > FilePath = "C:\currentpic.jpg"
    > myImage.Save(FilePath, Imaging.ImageFormat.Jpeg)
    > myImageCtrl.ImageUrl = FilePath
    >
    > This works fine on my dev box. But when I run the page using i.e. from
    > another computer it looks for the picture in c:\ on that computer!!
    >
    > the code generated to the browser is as follows:
    > </select><img id="DBAPictureBox1" src="C:\currentpic.jpg" border="0"
    > style="height:90px;width:120px;Z-INDEX: 106; LEFT: 480px; POSITION:
    > absolute; TOP: 192px" /><span id="MsgBox" style="color:Red;font-family:Times
    > New Roman;font-weight:bold;width:512px;Z-INDEX: 107; LEFT: 96px; POSITION:
    > absolute; TOP: 16px"></span>
    >
    > As can be seen, src is set to c:\currentpic.jpg.
    >
    > It seems, from all of this, that the notion of seting the imageURL property
    > to a file is bogus. Does anyone know how can I stream this binary image
    > from my database into a real URL?
    >
    >
    > (BTW, I realize C:\ is a bad place to put the .jpg and Steve Orr showed be a
    > way to save it to c:\inetpub\wwwroot\myproject\mycurrentpic.jpg but that
    > save won't even work on my dev box as it gets a GDI + exception but this is
    > really another problem)
    >
    > Thanks,
    > Gary
    >
    >
    Steve C. Orr, MCSD Guest

  4. #3

    Default Re: Image Web Form Control Problem

    My two sources of information on asp.net have been (1) the Wrox asp.net book and (2) the sdk docs. Every example of imageURL in both of those sources shows use with a file - not a single example shows use with a URL so that's probably how I got stuck on the idea of using a file. If I understand this correctly, none of those examples in the book or docs would work as they would look for the file on the machine running the browser. Maybe I got a bad book.

    Both of those sources also discuss response.outputstream.write in the context of writing back to the browser that made the request, since it's a response. Your recommendation is to use the response write to go write to another page on the server. I'm trying to understand your example code but it doesn't seem to be referencing myimage.aspx rather it seems to be writing back to the response stream which I understand to be going back to the browser that made the request. Anyway, thanks. I'll play around with this idea.
    Gary
    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message news:OyqxxHGWDHA.1620@TK2MSFTNGP12.phx.gbl...
    It's called ImageURL, not ImagePath.
    You need to give it a real URL, as in [url]http://www.mysite.com/myproject/myimage.aspx[/url]
    Then the myimage.aspx page should return nothing but the image.
    The page should also have the appropriate Response.ContentType set.
    Then you can reference reference your image page with a standard Image tag or Image control
    from your main page. <img src='myimage.aspx' ...>

    Assuming you are reading the image out of a database, the code would look something like this:

    Dim dr As System.Data.SqlClient.SqlDataReader


    Response.Clear

    cmdGetFile.Parameters("@File_ID").Value = Request("ImageID").ToString

    dbConn.Open()

    dr = cmdGetFile.ExecuteReader


    If dr.Read Then

    Response.ContentType = dr("ContentType").ToString

    Response.OutputStream.Write(CType(dr("FileData"), Byte()), 0, CInt(dr("FileSize")))

    Else

    Response.Write("File Not Found.")

    End If



    Here's more info:

    [url]http://www.aspnetpro.com/features/2003/07/asp200307so_f/asp200307so_f.asp[/url]



    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]





    "Gary B" <deanblakely@earthlink.net> wrote in message news:e7HzmPFWDHA.888@TK2MSFTNGP10.phx.gbl...
    > I have an asp.net application that retrieves a bitmap from my Sql Server
    > database and I an trying to put it into a web form image control.
    > Unfortunitely an image web form control won't handle a .net image type and
    > will only accept an image from a file set by the imageURL property.
    >
    > My tactic is to drag the image out of the sql server database, save it to a
    > file on my web server, and then set the imageURL property to that saved
    > file. Seemed like a good approach.
    >
    > For reasons beyond the scope of this issue, I am saving it as
    > C:\curentpic.jpg with the following code:
    >
    >
    > FilePath = "C:\currentpic.jpg"
    > myImage.Save(FilePath, Imaging.ImageFormat.Jpeg)
    > myImageCtrl.ImageUrl = FilePath
    >
    > This works fine on my dev box. But when I run the page using i.e. from
    > another computer it looks for the picture in c:\ on that computer!!
    >
    > the code generated to the browser is as follows:
    > </select><img id="DBAPictureBox1" src="C:\currentpic.jpg" border="0"
    > style="height:90px;width:120px;Z-INDEX: 106; LEFT: 480px; POSITION:
    > absolute; TOP: 192px" /><span id="MsgBox" style="color:Red;font-family:Times
    > New Roman;font-weight:bold;width:512px;Z-INDEX: 107; LEFT: 96px; POSITION:
    > absolute; TOP: 16px"></span>
    >
    > As can be seen, src is set to c:\currentpic.jpg.
    >
    > It seems, from all of this, that the notion of seting the imageURL property
    > to a file is bogus. Does anyone know how can I stream this binary image
    > from my database into a real URL?
    >
    >
    > (BTW, I realize C:\ is a bad place to put the .jpg and Steve Orr showed be a
    > way to save it to c:\inetpub\wwwroot\myproject\mycurrentpic.jpg but that
    > save won't even work on my dev box as it gets a GDI + exception but this is
    > really another problem)
    >
    > Thanks,
    > Gary
    >
    >
    Gary B Guest

  5. #4

    Default Re: Image Web Form Control Problem

    You must understand that there are two pages here for this to work.
    The main page has an HTML link to your "image" and the other page acts as the "image" by outputing only an image with no HTML.
    If you save the file to disk first, you can use Response.Writefile to output the image.
    Or you can skip saving the image to disk and output it directly by using Response.OutputStream.Write

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]


    "Gary B" <deanblakely@earthlink.net> wrote in message news:OzSFbPHWDHA.3232@tk2msftngp13.phx.gbl...
    My two sources of information on asp.net have been (1) the Wrox asp.net book and (2) the sdk docs. Every example of imageURL in both of those sources shows use with a file - not a single example shows use with a URL so that's probably how I got stuck on the idea of using a file. If I understand this correctly, none of those examples in the book or docs would work as they would look for the file on the machine running the browser. Maybe I got a bad book.

    Both of those sources also discuss response.outputstream.write in the context of writing back to the browser that made the request, since it's a response. Your recommendation is to use the response write to go write to another page on the server. I'm trying to understand your example code but it doesn't seem to be referencing myimage.aspx rather it seems to be writing back to the response stream which I understand to be going back to the browser that made the request. Anyway, thanks. I'll play around with this idea.
    Gary
    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message news:OyqxxHGWDHA.1620@TK2MSFTNGP12.phx.gbl...
    It's called ImageURL, not ImagePath.
    You need to give it a real URL, as in [url]http://www.mysite.com/myproject/myimage.aspx[/url]
    Then the myimage.aspx page should return nothing but the image.
    The page should also have the appropriate Response.ContentType set.
    Then you can reference reference your image page with a standard Image tag or Image control
    from your main page. <img src='myimage.aspx' ...>

    Assuming you are reading the image out of a database, the code would look something like this:

    Dim dr As System.Data.SqlClient.SqlDataReader


    Response.Clear

    cmdGetFile.Parameters("@File_ID").Value = Request("ImageID").ToString

    dbConn.Open()

    dr = cmdGetFile.ExecuteReader


    If dr.Read Then

    Response.ContentType = dr("ContentType").ToString

    Response.OutputStream.Write(CType(dr("FileData"), Byte()), 0, CInt(dr("FileSize")))

    Else

    Response.Write("File Not Found.")

    End If



    Here's more info:

    [url]http://www.aspnetpro.com/features/2003/07/asp200307so_f/asp200307so_f.asp[/url]



    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]





    "Gary B" <deanblakely@earthlink.net> wrote in message news:e7HzmPFWDHA.888@TK2MSFTNGP10.phx.gbl...
    > I have an asp.net application that retrieves a bitmap from my Sql Server
    > database and I an trying to put it into a web form image control.
    > Unfortunitely an image web form control won't handle a .net image type and
    > will only accept an image from a file set by the imageURL property.
    >
    > My tactic is to drag the image out of the sql server database, save it to a
    > file on my web server, and then set the imageURL property to that saved
    > file. Seemed like a good approach.
    >
    > For reasons beyond the scope of this issue, I am saving it as
    > C:\curentpic.jpg with the following code:
    >
    >
    > FilePath = "C:\currentpic.jpg"
    > myImage.Save(FilePath, Imaging.ImageFormat.Jpeg)
    > myImageCtrl.ImageUrl = FilePath
    >
    > This works fine on my dev box. But when I run the page using i.e. from
    > another computer it looks for the picture in c:\ on that computer!!
    >
    > the code generated to the browser is as follows:
    > </select><img id="DBAPictureBox1" src="C:\currentpic.jpg" border="0"
    > style="height:90px;width:120px;Z-INDEX: 106; LEFT: 480px; POSITION:
    > absolute; TOP: 192px" /><span id="MsgBox" style="color:Red;font-family:Times
    > New Roman;font-weight:bold;width:512px;Z-INDEX: 107; LEFT: 96px; POSITION:
    > absolute; TOP: 16px"></span>
    >
    > As can be seen, src is set to c:\currentpic.jpg.
    >
    > It seems, from all of this, that the notion of seting the imageURL property
    > to a file is bogus. Does anyone know how can I stream this binary image
    > from my database into a real URL?
    >
    >
    > (BTW, I realize C:\ is a bad place to put the .jpg and Steve Orr showed be a
    > way to save it to c:\inetpub\wwwroot\myproject\mycurrentpic.jpg but that
    > save won't even work on my dev box as it gets a GDI + exception but this is
    > really another problem)
    >
    > Thanks,
    > Gary
    >
    >
    Steve C. Orr, MCSD Guest

  6. #5

    Default Re: Image Web Form Control Problem

    I understand that - now. What I don't understand is : in Request("ImageID").ToString, where ImageID is coming from. Also, I'm having a hard time believing that we can't write files to disk and read them again on the server. If we could do that, I could just use the ..jpg file I wrote to disk and avoid all of this complexity. Since all of the docs and the book I have use imageURL with files, I don't think I'm ready to believe that it can't be done.

    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message news:%23QYdfTHWDHA.1780@TK2MSFTNGP11.phx.gbl...
    You must understand that there are two pages here for this to work.
    The main page has an HTML link to your "image" and the other page acts as the "image" by outputing only an image with no HTML.
    If you save the file to disk first, you can use Response.Writefile to output the image.
    Or you can skip saving the image to disk and output it directly by using Response.OutputStream.Write

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]


    "Gary B" <deanblakely@earthlink.net> wrote in message news:OzSFbPHWDHA.3232@tk2msftngp13.phx.gbl...
    My two sources of information on asp.net have been (1) the Wrox asp.net book and (2) the sdk docs. Every example of imageURL in both of those sources shows use with a file - not a single example shows use with a URL so that's probably how I got stuck on the idea of using a file. If I understand this correctly, none of those examples in the book or docs would work as they would look for the file on the machine running the browser. Maybe I got a bad book.

    Both of those sources also discuss response.outputstream.write in the context of writing back to the browser that made the request, since it's a response. Your recommendation is to use the response write to go write to another page on the server. I'm trying to understand your example code but it doesn't seem to be referencing myimage.aspx rather it seems to be writing back to the response stream which I understand to be going back to the browser that made the request. Anyway, thanks. I'll play around with this idea.
    Gary
    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message news:OyqxxHGWDHA.1620@TK2MSFTNGP12.phx.gbl...
    It's called ImageURL, not ImagePath.
    You need to give it a real URL, as in [url]http://www.mysite.com/myproject/myimage.aspx[/url]
    Then the myimage.aspx page should return nothing but the image.
    The page should also have the appropriate Response.ContentType set.
    Then you can reference reference your image page with a standard Image tag or Image control
    from your main page. <img src='myimage.aspx' ...>

    Assuming you are reading the image out of a database, the code would look something like this:

    Dim dr As System.Data.SqlClient.SqlDataReader


    Response.Clear

    cmdGetFile.Parameters("@File_ID").Value = Request("ImageID").ToString

    dbConn.Open()

    dr = cmdGetFile.ExecuteReader


    If dr.Read Then

    Response.ContentType = dr("ContentType").ToString

    Response.OutputStream.Write(CType(dr("FileData"), Byte()), 0, CInt(dr("FileSize")))

    Else

    Response.Write("File Not Found.")

    End If



    Here's more info:

    [url]http://www.aspnetpro.com/features/2003/07/asp200307so_f/asp200307so_f.asp[/url]



    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]





    "Gary B" <deanblakely@earthlink.net> wrote in message news:e7HzmPFWDHA.888@TK2MSFTNGP10.phx.gbl...
    > I have an asp.net application that retrieves a bitmap from my Sql Server
    > database and I an trying to put it into a web form image control.
    > Unfortunitely an image web form control won't handle a .net image type and
    > will only accept an image from a file set by the imageURL property.
    >
    > My tactic is to drag the image out of the sql server database, save it to a
    > file on my web server, and then set the imageURL property to that saved
    > file. Seemed like a good approach.
    >
    > For reasons beyond the scope of this issue, I am saving it as
    > C:\curentpic.jpg with the following code:
    >
    >
    > FilePath = "C:\currentpic.jpg"
    > myImage.Save(FilePath, Imaging.ImageFormat.Jpeg)
    > myImageCtrl.ImageUrl = FilePath
    >
    > This works fine on my dev box. But when I run the page using i.e. from
    > another computer it looks for the picture in c:\ on that computer!!
    >
    > the code generated to the browser is as follows:
    > </select><img id="DBAPictureBox1" src="C:\currentpic.jpg" border="0"
    > style="height:90px;width:120px;Z-INDEX: 106; LEFT: 480px; POSITION:
    > absolute; TOP: 192px" /><span id="MsgBox" style="color:Red;font-family:Times
    > New Roman;font-weight:bold;width:512px;Z-INDEX: 107; LEFT: 96px; POSITION:
    > absolute; TOP: 16px"></span>
    >
    > As can be seen, src is set to c:\currentpic.jpg.
    >
    > It seems, from all of this, that the notion of seting the imageURL property
    > to a file is bogus. Does anyone know how can I stream this binary image
    > from my database into a real URL?
    >
    >
    > (BTW, I realize C:\ is a bad place to put the .jpg and Steve Orr showed be a
    > way to save it to c:\inetpub\wwwroot\myproject\mycurrentpic.jpg but that
    > save won't even work on my dev box as it gets a GDI + exception but this is
    > really another problem)
    >
    > Thanks,
    > Gary
    >
    >
    Gary B Guest

  7. #6

    Default Re: Image Web Form Control Problem

    Oh, this thread is so active. I hope I could have some input on it. Unfornately I am new to web developments.
    Can you please go to my thread
    [url]http://www.developersdex.com/asp/message.asp?r=3265334&p=1116[/url]
    and let me know your opinion?
    Thanks

    Jerry


    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message news:OUQPF0HWDHA.1644@TK2MSFTNGP10.phx.gbl...
    In that example the Image ID is being passed on the querystring.
    So the full ImageURL would be something like:
    [url]http://www.myserver.com/myproject/myimage.aspx?ImageID=14[/url]

    Of course you can read and write files on the server! What's hard to believe about that?
    If youv'e successfully saved your jpg to the server hard drive then you can skip the database code I listed and instead use Response.Writefile from the myimage.aspx page.
    Here's more info:
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhttpresponseclasswritefiletopic1.asp[/url]

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]


    "Gary B" <deanblakely@earthlink.net> wrote in message news:epfJjrHWDHA.2360@TK2MSFTNGP12.phx.gbl...
    I understand that - now. What I don't understand is : in Request("ImageID").ToString, where ImageID is coming from. Also, I'm having a hard time believing that we can't write files to disk and read them again on the server. If we could do that, I could just use the ..jpg file I wrote to disk and avoid all of this complexity. Since all of the docs and the book I have use imageURL with files, I don't think I'm ready to believe that it can't be done.

    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message news:%23QYdfTHWDHA.1780@TK2MSFTNGP11.phx.gbl...
    You must understand that there are two pages here for this to work.
    The main page has an HTML link to your "image" and the other page acts as the "image" by outputing only an image with no HTML.
    If you save the file to disk first, you can use Response.Writefile to output the image.
    Or you can skip saving the image to disk and output it directly by using Response.OutputStream.Write

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]


    "Gary B" <deanblakely@earthlink.net> wrote in message news:OzSFbPHWDHA.3232@tk2msftngp13.phx.gbl...
    My two sources of information on asp.net have been (1) the Wrox asp.net book and (2) the sdk docs. Every example of imageURL in both of those sources shows use with a file - not a single example shows use with a URL so that's probably how I got stuck on the idea of using a file. If I understand this correctly, none of those examples in the book or docs would work as they would look for the file on the machine running the browser. Maybe I got a bad book.

    Both of those sources also discuss response.outputstream.write in the context of writing back to the browser that made the request, since it's a response. Your recommendation is to use the response write to go write to another page on the server. I'm trying to understand your example code but it doesn't seem to be referencing myimage.aspx rather it seems to be writing back to the response stream which I understand to be going back to the browser that made the request. Anyway, thanks. I'll play around with this idea.
    Gary
    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message news:OyqxxHGWDHA.1620@TK2MSFTNGP12.phx.gbl...
    It's called ImageURL, not ImagePath.
    You need to give it a real URL, as in [url]http://www.mysite.com/myproject/myimage.aspx[/url]
    Then the myimage.aspx page should return nothing but the image.
    The page should also have the appropriate Response.ContentType set.
    Then you can reference reference your image page with a standard Image tag or Image control
    from your main page. <img src='myimage.aspx' ...>

    Assuming you are reading the image out of a database, the code would look something like this:

    Dim dr As System.Data.SqlClient.SqlDataReader


    Response.Clear

    cmdGetFile.Parameters("@File_ID").Value = Request("ImageID").ToString

    dbConn.Open()

    dr = cmdGetFile.ExecuteReader


    If dr.Read Then

    Response.ContentType = dr("ContentType").ToString

    Response.OutputStream.Write(CType(dr("FileData"), Byte()), 0, CInt(dr("FileSize")))

    Else

    Response.Write("File Not Found.")

    End If



    Here's more info:

    [url]http://www.aspnetpro.com/features/2003/07/asp200307so_f/asp200307so_f.asp[/url]



    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]





    "Gary B" <deanblakely@earthlink.net> wrote in message news:e7HzmPFWDHA.888@TK2MSFTNGP10.phx.gbl...
    > I have an asp.net application that retrieves a bitmap from my Sql Server
    > database and I an trying to put it into a web form image control.
    > Unfortunitely an image web form control won't handle a .net image type and
    > will only accept an image from a file set by the imageURL property.
    >
    > My tactic is to drag the image out of the sql server database, save it to a
    > file on my web server, and then set the imageURL property to that saved
    > file. Seemed like a good approach.
    >
    > For reasons beyond the scope of this issue, I am saving it as
    > C:\curentpic.jpg with the following code:
    >
    >
    > FilePath = "C:\currentpic.jpg"
    > myImage.Save(FilePath, Imaging.ImageFormat.Jpeg)
    > myImageCtrl.ImageUrl = FilePath
    >
    > This works fine on my dev box. But when I run the page using i.e. from
    > another computer it looks for the picture in c:\ on that computer!!
    >
    > the code generated to the browser is as follows:
    > </select><img id="DBAPictureBox1" src="C:\currentpic.jpg" border="0"
    > style="height:90px;width:120px;Z-INDEX: 106; LEFT: 480px; POSITION:
    > absolute; TOP: 192px" /><span id="MsgBox" style="color:Red;font-family:Times
    > New Roman;font-weight:bold;width:512px;Z-INDEX: 107; LEFT: 96px; POSITION:
    > absolute; TOP: 16px"></span>
    >
    > As can be seen, src is set to c:\currentpic.jpg.
    >
    > It seems, from all of this, that the notion of seting the imageURL property
    > to a file is bogus. Does anyone know how can I stream this binary image
    > from my database into a real URL?
    >
    >
    > (BTW, I realize C:\ is a bad place to put the .jpg and Steve Orr showed be a
    > way to save it to c:\inetpub\wwwroot\myproject\mycurrentpic.jpg but that
    > save won't even work on my dev box as it gets a GDI + exception but this is
    > really another problem)
    >
    > Thanks,
    > Gary
    >
    >
    Jerry Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139