用DirctoryInfo.GetFiles("*.jpg")就可
绑定到一个repeater.
string sPath = Server.MapPath("pic");
DirectoryInfo dir = new DirectoryInfo(sPath);
FileInfo[] fs = dir.GetFiles(sDate + "*.jpg");
this.rpList.DataSource = fs;
this.rpList.DataBind()
绑定到一个repeater.
string sPath = Server.MapPath("pic");
DirectoryInfo dir = new DirectoryInfo(sPath);
FileInfo[] fs = dir.GetFiles(sDate + "*.jpg");
this.rpList.DataSource = fs;
this.rpList.DataBind()
解决方案 »
- 求助关于数据库的问题
- DataTable的select 方法的筛选表达式怎么写?
- 安装了VS2005后为何无ASPNET等用户的问题?
- 我安装的vsnet2003打不开下载的文件,提示文件是用更高版本的建立的
- 请教高手!如何在WEB项目里调用windows项目????
- 谁能帮忙调下基于ASP.NET的OA,VS2005+SQL2005的,不能注册用户。
- asp.net快速入门中示例不能运行??
- 请问c#里有么有直接把一个分数转为百分数的函数?
- 各位大侠们:论坛里面的等级\经验\财产\魅力\等是怎么样实现的呀!给一下思路或者源码给参考下下,好不好呀
- 请教怎么使ASP.net的dropdownlist控件可编辑?
- 【HELP】AdRotator控件的问题
- vs2005 c#中调用vc写的dll文件出错
<img onclick="javascript:document.getElementById('TEXT1').value='/pic/<%#GetName(Container.DataItem)%>' " src='/pic/<%#GetName(Container.DataItem)%>' >后台:
protected string GetName(object o)
{
FileInfo f = (FileInfo)o;
return f.Name;
}
代码可否再全一点。谢谢咯。新手。勿怪。。
为什么是<img onclick ?
用button可以吗?
报错了。
能否用text和button再写下。
谢谢咯。
先点击button读文件夹文件。
然后选择文件。
然后text读其路径。
<input type='button' onclick="javascript:document.getElementById('TEXT1').value='/pic/<%#GetName(Container.DataItem)%>' value='选择'>
<%#GetName(Container.DataItem)%>
<ItemTemplate>
string tmpFullPath=Server.MapPath();
tmpFullPath=+file;
Request.Files["UploadFile1"].SaveAs(tmpFullPath);图片浏览代码:
if (File.Exists(filePath))
{
System.Drawing.Image image = System.Drawing.Image.FromFil(tmpFullPath);
this.pictureBox1.Image = image; //用PictureBox显示上传的图片
}
报错了。
<ItemTemplate>
<input type='button' onclick="javascript:document.getElementById('txtSmallPic').value='/pic/<%#GetName(Container.DataItem)%>'" value='选择'>
<%#GetName(Container.DataItem)%>
</ItemTemplate>
</asp:Repeater>
我只知道按扭读取文件夹,取文件。然后把路径传走。
这里数据绑定应该绑定谁啊?
绑定到一个repeater.
string sPath = Server.MapPath("pic");
DirectoryInfo dir = new DirectoryInfo(sPath);
FileInfo[] fs = dir.GetFiles(sDate + "*.jpg");
this.rpList.DataSource = fs;
this.rpList.DataBind()
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="EssentialDemo.PhotoReader._Default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Default</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:button id="Button1" runat="server" Text="Get"></asp:button><asp:repeater id="rptFileList" runat="server">
<ItemTemplate>
<asp:LinkButton ID="FileName" Runat="server"></asp:LinkButton>
</ItemTemplate>
</asp:repeater><asp:label id="lblFileUrl" runat="server"></asp:label></form>
</body>
</HTML>后台:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace EssentialDemo.PhotoReader
{
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Repeater rptFileList;
protected System.Web.UI.WebControls.Label lblFileUrl;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.rptFileList.ItemCommand += new System.Web.UI.WebControls.RepeaterCommandEventHandler(this.rptPicList_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string sPath = Server.MapPath("./");
DirectoryInfo dir = new DirectoryInfo(sPath);
FileInfo[] fs = dir.GetFiles("*");
rptFileList.DataSource = fs;
rptFileList.DataBind();
for(int i = 0; i < rptFileList.Items.Count; i ++)
{
(rptFileList.Items[i].FindControl("FileName") as LinkButton).Text = fs[i].Name;
}
} private void rptPicList_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
lblFileUrl.Text = (e.Item.FindControl("FileName") as LinkButton).Text;
}
}
}