菜鸟问题(asp.net2.0)按文件名查找文件 急!!!! 各位大虾,现小弟有一页面,输入字符串,按“查询”按钮,到指定目录下(许多文件),按照输入字符串和文件名匹配进行查找。如找到则在查询页面显示文件路径,并提供下载。怎么实现??谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DirectoryInfo directInfo = new DirectoryInfo(dri) if (directInfo.Exists) { FileSystemInfo[] path = directInfo.GetFileSystemInfos() if (path.Length != 0) { foreach (FileSystemInfo file in path) { Response.Write(file.Name); //显示文件或路径名 Response.Write(file.FullName);//显示文件或路径全名 //然后在这里判断是否有该文件,有,则提取相对路径 } } } 注意:该路径必须具有相应权限,2000为ASPNE权限,2003为NETWORKSERVICE权限 seaonce(雨花中的小皮鞋) 能否具体指导一下谢谢msn:[email protected] 使用System.IO.Directory.GetFiles(string path,string searchPattern)这个方法,详细内容请看MSDN 比如:查找当前目录下所有aspx文件 System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Server.MapPath("")); System.IO.FileInfo[] fs = dir.GetFiles("*.aspx"); foreach(System.IO.FileInfo f in fs) { Response.Write(f.Name +"<BR>"); } Click the link to solve your problem.Good luck! html标记问题 ASP.net中AJAX的Autocomplete控件被IE自动提示栏遮挡,怎么办? JW Player 如何加载srt字幕 新手问几个问题,帮帮忙啊! 一VML源代码,请帮我看一下呀! Gridview 动态添加删除行 asp.net 获取自定义控件的变量值 什么容器内的html代码不被解析? asp.net自动生成的TextBox不会SaveTextViewState的问题 可否利用DataGrid一次“添加”多条记录? 怎样远程发布网站 我很迷茫,大哥大姐们给指点一下吧,小弟在这里谢谢大家了
if (directInfo.Exists)
{
FileSystemInfo[] path = directInfo.GetFileSystemInfos()
if (path.Length != 0)
{
foreach (FileSystemInfo file in path)
{
Response.Write(file.Name); //显示文件或路径名
Response.Write(file.FullName);//显示文件或路径全名
//然后在这里判断是否有该文件,有,则提取相对路径
}
}
} 注意:该路径必须具有相应权限,2000为ASPNE权限,2003为NETWORKSERVICE权限
msn:[email protected]
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Server.MapPath(""));
System.IO.FileInfo[] fs = dir.GetFiles("*.aspx");
foreach(System.IO.FileInfo f in fs)
{
Response.Write(f.Name +"<BR>");
}