asp.net批量生成图片网页!
比如在图片文件夹下写一个asp 文件,
<script>
var i;
for(i=1;i <1000;i++)
{
document.write( " <img src=0 "+i+ ".jpg> ");
}
</script>
这样的前提是图片文件是有规律的01.jpg 02.jpg 03.jpg........
如果是没有规律的命名怎么用asp.net 实现呢?谢谢指点迷津!
------解决方案--------------------什么生成图片网页 你的意思就是遍历 文件夹下所有图片 显示出来对吧。。]
看下面的代码
后台代码
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();
}
}
前台代码:
<%@ 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> 遍历文件夹下所有图片 </title>
</head>
<body>
<form runat= "server ">
<div>
<asp:DataList runat= "server " RepeatColumns= "3 ">
<ItemTemplate>
<asp:image runat= "server " width= "120 " ImageUrl= ' <%# "images/ " +Eval( "Name ")%> '/>
</ItemTemplate>
</asp:DataList> </div>
</form>
</body>
</html>
------解决方案--------------------后台:
DirectoryInfo imagesfile = new DirectoryInfo(Server.MapPath( "./UploadFile "));
//获取文件路径
DataTable dtPicture = new DataTable();
dtPicture.Columns.Add( "FileName ");
dtPicture.Columns.Add( "Name ");
FileInfo[] files = imagesfile.GetFiles();
foreach(FileInfo file in files)
{
DataRow NewRow = dtPicture.NewRow();
NewRow[ "FileName "] = file.FullName;
NewRow[ "Name "] = file.Name;
dtPicture.Rows.Add(NewRow);
}
dl_Picture.DataSource = dtPicture;
dl_Picture.DataBind();
前台:
<asp:DataList ID= "dl_Picture " runat= "server " HorizontalAlign= "Center " RepeatColumns= "6 "
RepeatDirection= "Horizontal " OnEditCommand= "dl_Delete ">
<ItemTemplate>
<table cellpadding= "0 " cellspacing= "0 " border= "0 ">
<tr>