ASP. NET2.0 traverses all images in the folder [original by month]

Source: Internet
Author: User

ASP. NET2.0 traverses all images in the folder

Author: qingyueer

Home page:Http://blog.csdn.net/21aspnet/Time: 2007.4.4


1. The following directory contains several images (all of which are big images)

2. display on the page

3. Code

Background code
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Runtime. Remoting;
Using System. Runtime. Remoting. Lifetime;
Using System. IO;

Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
DirectoryInfo imagesfile = new DirectoryInfo (Server. MapPath ("./images "));
Datalist1.datasource = imagesfile. getfiles ("*. jpg ");
Datalist1.databind ();

}

}

Front-end code:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> traverse all the pictures under the folder http://blog.csdn.net/21aspnet clear moon </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
& Nbsp; <asp: datalist id = "datalist1" runat = "server" repeatcolumns = "3">
<Itemtemplate>
<Asp: Image id = "image1" runat = "server" width = "120" imageurl = '<% # "images/" + eval ("name ") %> '/>
</Itemtemplate>
</ASP: datalist> </div>
</Form>
</Body>
</Html>

Note: If you want to generate a real thumbnail, it must be generated on another page.
Imageurl = '<% # "AAA. aspx: Obtain the generated result. Refer to the following code:

 

Example:Simpleimagehandler. ashx
<% @ WebHandler Language = "C #" Class = "SimpleImageHandler" %>

Using System;
Using System. Drawing;
Using System. Drawing. Imaging;
Using System. IO;
Using System. Web;
Using System. Web. Caching;

Public class SimpleImageHandler: IHttpHandler {

Public void ProcessRequest (HttpContext context)
{
// Load image.
Bitmap bmap = new Bitmap (@ "C:/Temp/TEST. JPG ");

// You cocould do something here, e.g. add some texts to image.

// Send back image.
Context. Response. ContentType = "image/jpeg ";
Context. Response. BufferOutput = false;
Bmap. Save (context. Response. OutputStream, ImageFormat. Jpeg );
}

Public bool IsReusable
{
Get
{
Return false;
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.