using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
private bool bExist;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (tbInput.Text.Trim() == "")
{
tbInput.Text = "不存在此文件!";
return;
}
string[] drives = System.IO.Directory.GetLogicalDrives();
foreach (string str in drives)
{
if (ProcessDirectory(str))
break;
}
if (!bExist)
tbInput.Text = "不存在此文件!";
}
catch (System.IO.IOException)
{
Response.Write("I/O错误!");
}
catch (System.Security.SecurityException)
{
Response.Write("没有访问权限!");
}
}
public bool ProcessDirectory(string targetDirectory)
{
try
{
// Process the list of files found in the directory
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
{
if (ProcessFile(fileName))
return true;
}
// Recurse into subdirectories of this directory
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
{
if (ProcessDirectory(subdirectory))
return true;
}
return false;
}
catch(Exception)
{
return false;
}
}
public bool ProcessFile(string strFileName)
{
if (Path.GetFileName(strFileName).ToLower() == tbInput.Text.Trim().ToLower())
{
tbInput.Text = strFileName.ToLower();
bExist = true;
return true;
}
else
return false;
}
}
分享到:
相关推荐
C#文件操作类
c#文件操作c#文件操作c#文件操作c#文件操作
c#对文件或者文件夹全面的操作。以及c#对文件操作方面的一些属性的概述。
用C#操作Office等办公软件,如Excel、Word、Text、Xml文档的创建,读取,写入,保存等,来进行数据的保存与读取。
C#文件操作大全
c#文件操作c#文件操作c#文件操作c#文件操作
C#文件操作小例程,是好个例子
c#文件操作类,读取,写入;根据传入的虚拟路径或物理路径获取文件、目录;
C#文件操作方法大全.pdf,
C#文件操作 比较详细 C#文件操作 比较详细 C#文件操作 比较详细 C#文件操作 比较详细
C#显示文件属性信息,C#文件操作类C#显示文件属性信息,C#文件操作类C#显示文件属性信息,C#文件操作类C#显示文件属性信息,C#文件操作类
Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录)
C# 文件 操作 方法 大全C# 文件 操作 方法 大全C# 文件 操作 方法 大全C# 文件 操作 方法 大全C# 文件 操作 方法 大全C# 文件 操作 方法 大全C# 文件 操作 方法 大全
对C#中的各种文件操作方法进行了归纳,并结合实例进行了讲解
C#文件操作,基本的操作 C#文件操作,基本的操作
C#文件操作大全.pdf,超清晰,内容超全,与大家共享,一同进步!
包括: <br>F运行程序或文件 F使路径合法化 F使目录合法化 F根据网址重命名 F删除文件 F移动文件 F删除目录 F复制文件 F获取程序所在目录 F提取文件名 F根据文件名提取文件...
关于C#文件操作使用的一些心得,希望可以帮助大家!
描述了几种常用的C# 文件操作方法,使你对用C#操作文件非常容易上手