Simple Image Slide Show C # edition

Source: Internet
Author: User
Simple Image Slide Show C # edition

By Hehong Yang (Yang Heohong)

In Scott Mitchell's article, he create a simple-image slide show using asp.net with vb.net. Now I rewrite it in C #. I Create a sub directory Photos to store the image files. And instead of using DataList control, I used DropDownList control to list all image files. I use it to personal web site, so can view a live demo there (http://www17.brinkster.com/flycrane/Album/default.asp x).

Soure code:Default.aspx

<%@ Page language= "C #"%>

<%@ Import namespace= "System.IO"%>

<script runat= "Server" >

Insert page code here

private void Page_Load (object sender, System.EventArgs e)

{

Get list of images

DirectoryInfo dirinfo= New DirectoryInfo (Server.MapPath ("Photos"));

Fileinfo[] images= Imagesfilter (Dirinfo.getfiles ());

Determine the current image to show

int imageindex= 0;

if (request.querystring["N"]!=null)

imageindex= Convert.ToInt32 (request.querystring["N"]);

lbltitle.text+= path.getfilenamewithoutextension (Images[imageindex). Name)

+ "(" + (imageindex+1) + "of" +images. length+ ")";

Currentimage.imageurl= "/flycrane/album/photos/" +images[imageindex]. Name;

if (imageindex>0)

Lnkprev.navigateurl= "Default.aspx?" N= "+ (imageIndex-1);

if (imageindex<images. LENGTH-1)

Lnknext.navigateurl= "Default.aspx?" N= "+ (ImageIndex + 1);

if (! IsPostBack)

{

Ddlimages.datasource= images;

Ddlimages.databind ();

}





}

Public fileinfo[] Imagesfilter (fileinfo[] files)

{

ArrayList newimages= new ArrayList (Files. Length);

for (int i=0;i<files. length;i++)

{

if (Path.getextension (files[i). Name.tolower ()) = = ". jpg" | |

Path.getextension (Files[i]. Name.tolower ()) = = ". jpeg" | |

Path.getextension (Files[i]. Name.tolower ()) = = ". png" | |

Path.getextension (Files[i]. Name.tolower ()) = = ". gif"

)

Newimages.add (Files[i]);

}

Return (fileinfo[]) Newimages.toarray (Files[0]. GetType ());

}

void Ddlimages_selectedindexchanged (object sender, EventArgs e) {

Response.Redirect ("default.aspx?") N= "+ (Ddlimages.selectedindex));

}

</script>



<title>flycrane ' s Personal Web site</title>

<link rel= "stylesheet" src= "/flycrane/styles/flycrane.css"/>


<body>

<form runat= "Server" >

<table cellspacing= "0" cellpadding= "0" width= "765" align= "center" border= "0" >

<!--dwlayouttable-->

<tbody>

<tr>

&LT;TD align= "Middle" width= "765" bgcolor= "#9999cc" >

<asp:label id= "Lbltitle" runat= "Server" width= "206px" >you are viewing: </asp:Label></td>

</tr>

<tr>

&LT;TD align= "Middle" width= "765" >

<p>

<asp:image id= "Currentimage" runat= "Server" ></asp:Image>

</p>

</td>

</tr>

<tr>

&LT;TD align= "Middle" width= "765" bgcolor= "#9999cc" >

<asp:hyperlink id= "Lnkprev" runat= "Server" >Previous</asp:HyperLink>

<asp:hyperlink id= "Lnknext" runat= "Server" >Next</asp:HyperLink>

</td>

</tr>

<tr>

&LT;TD align= "Middle" width= "765" bgcolor= "#9999cc" >

Select One Photo:

<asp:dropdownlist id= "ddlimages" runat= "Server" onselectedindexchanged= "ddlimages_selectedindexchanged" autopostback= "True" ></asp:DropDownList>

</td>

</tr>

</tbody>

</table>

</form>

</body>




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.