Using Embedded Images in ASP.Net
<%@ Page Language="C#" %> <% string image = string.Empty; string asmName = string.Empty; try { Response.Clear(); // Get Image Name from request image = Request["img"].Replace("/", "."); // Get Assembly Name from request asmName = Request["asm"]; // Default the Assembly Name to the current assembly if(asmName == null || asmName == string.Empty) asmName = this.GetType().Assembly.FullName; // Load the Assembly System.Reflection.Assembly asm = System.Reflection.Assembly.Load(asmName); // Get the Image stream from the embedded image System.IO.Stream stream = asm.GetManifestResourceStream(image); // Create an Image object from the stream System.Drawing.Image img = System.Drawing.Image.FromStream(stream); // Save the Image stream to the output stream img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); } catch(Exception ex) { Response.Write("Exception: <BR>image = " + image + "<BR>asmName = " + asmName + "<BR>" + ex.Message + "<BR>" + ex.StackTrace.Replace("\n", "<BR>")); } finally { Response.End(); } %>
<IMG src="image.aspx?asm=<AssemblyName>&img=<namespace>.testimage.gif" />
This will prevent me from having to copy all the images; all I would need to copy is the Assembly and the image.aspx file. What do you guys think? Does anyone see any potential problems with this?