This blog post teaches you how to display pictures in a non-site directory, you can display pictures of all the drive directories on the server where the site resides, and a picture that maps the network disk path. Here are two examples, one is to show the picture under D disk, another example is to show the Map network path picture.
Most practical in the enterprise, the occasional need for temporary display pictures, but users do not want to upload a large number of pictures, but placed on a workstation. So you need to map the path, or you can copy it directly to a certain drive on the server.
The following example shows a picture of a mapped network disk directory:
You can create a ashx file to work with pictures (core code):
Showoutsiteimage.ashx
Copy Code code as follows:
<%@ WebHandler language= "C #" class= "Insus.NET.ShowOutSiteImage"%>
Using System;
Using System.Web;
Using System.IO;
Namespace Insus.net
{
public class Showoutsiteimage:ihttphandler
{
public void ProcessRequest (HttpContext context)
{
String parameter = context. request.querystring["File"];
FileStream fs = new FileStream (parameter, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader (FS);
byte[] bytes = br. Readbytes ((Int32) fs. Length);
Br. Close ();
Fs. Close ();
Context. Response.OutputStream.Write (bytes, 0, bytes. Length);
}
public bool IsReusable
{
Get
{
return false;
}
}
}
}
When you need to display a picture, the following HTML "picture path" syntax, you can refer to the above two screenshots.
Copy Code code as follows:
<asp:image id= "Image1" runat= "Server" imageurl= "~/showoutsiteimage.ashx?file= picture path"/>