How to use embedded image in ASP.NET Server Control

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

  1. #1

    Default How to use embedded image in ASP.NET Server Control

    I have a server control, written in ASP.NET, where I added two images
    as "Embedded Resource" to it.
    Now, I need to find a way to read the resource and produce an output
    stream to have the image be displayed on the web page as a regular
    image HTML tag such as "<img src='myResourceImage.gif'>".

    Any help is greatly appreciated.

    Thanks in advanvce.

    Oliver
    Oliver Degnan Guest

  2. Similar Questions and Discussions

    1. Custom Server Control Embedded in a DataGrid Event problem
      Hi All, I have successfully created a Custom Server Control which is a Table that has an ImageButton in one of it's cells. When I use this...
    2. Databind an embedded control in an embedded datagrid
      All, I have something like the following: Datagrid1 Col1 - bound column Col2 - template column Datagrid1_OnItemDataBound datagrid2 -...
    3. Can a URL be embedded in an image itself?
      ImageReady documentation seems to indicatate that a URL can be assigned to an image, but it only seems to work if one also exports the HTML code with...
    4. what format is an embedded image
      No info for embedded object in AI10 either, guys.
    5. Page Load fired 3 times Web user control is embedded in a custom control
      Hi, I have built a custom control that build a table with 3 cells in it. The custom control is designed to add all child controls to cell#2,...
  3. #2

    Default Re: How to use embedded image in ASP.NET Server Control

    Hi,

    to serve the image, you need to have custom Httphandler that would get it
    from the resource files (image is separate resource from HTML itself, so it
    needs to be requested separately). Anyway, you'd get the resource by using
    Assembly.GetManifestResourceStream.
    For example Andy Smith has following code in his FirstFocus control to get
    embedded js file:

    using (System.IO.StreamReader reader = new
    System.IO.StreamReader(typeof(FirstFocus).Assembly .GetManifestResourceStream(typeof(FirstFocus),
    "FirstFocusScript.js"))) {

    String script = "<script language='javascript' type='text/javascript'
    >\r\n<!--\r\n" + reader.ReadToEnd() + "\r\n//-->\r\n</script>";
    this.Page.RegisterClientScriptBlock(pageScriptName , script);

    }

    Because you have image, you of course read it as stream, not as text.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist









    "Oliver Degnan" <odegnan@dmghost.com> wrote in message
    news:e6c0b57d.0402121242.49bd20fa@posting.google.c om...
    I have a server control, written in ASP.NET, where I added two images
    as "Embedded Resource" to it.
    Now, I need to find a way to read the resource and produce an output
    stream to have the image be displayed on the web page as a regular
    image HTML tag such as "<img src='myResourceImage.gif'>".

    Any help is greatly appreciated.

    Thanks in advanvce.

    Oliver


    Teemu Keiski Guest

  4. #3

    Default Re: How to use embedded image in ASP.NET Server Control

    Thank you very much. I was able to acomplish the task with:

    hc.Response.ContentType = "image/" + strType;

    asm = Assembly.GetExecutingAssembly();
    ReadBinaryResource(asm.GetManifestResourceStream(
    cImageResPath + strResName), out byImage, out nLen);
    hc.Response.OutputStream.Write(byImage, 0, nLen);



    Oliver

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Oliver Degnan Guest

Posting Permissions

  • You may not post new threads
  • You may not 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