//
实例:
/**//// <summary>
/// 上传文件,上传成功后归来二个 string 型的所上传文件名 上传文件不能够当先3.5M
/// </summary>
/// <param name=”UpFileInput”>上传文件所用的控件的ID</param>
/// <param name=”FileSavePath”>上传文件保留的渠道(与上传页的绝对路线)</param>
/// <param name=”P”>Web窗体页</param>
/// <returns>上传文件的公文名 String</returns>
public string PubUpFile(System.Web.UI.HtmlControls.HtmlInputFile UpFileInput,string FileSavePath,Page P)
{
if(UpFileInput.PostedFile.ContentLength < 3000 * 1024)
{
//检查提供的目录是或不是留存,如空中楼阁则开创
PubExDirectory(FileSavePath,P);
//获娶上传文件的公文名,并保留到钦点的目录
string UpFileName;
if(UpFileInput.PostedFile.FileName.LastIndexOf(“\”) != -1)
{
UpFileName = UpFileInput.PostedFile.FileName.Substring(UpFileInput.PostedFile.FileName.LastIndexOf(“\”),UpFileInput.PostedFile.FileName.Length – UpFileInput.PostedFile.FileName.LastIndexOf(“\”));
}
else
{
UpFileName = “\” + UpFileInput.PostedFile.FileName;
}
UpFileInput.PostedFile.SaveAs(P.Server.MapPath(FileSavePath + UpFileName));
return FileSavePath + UpFileName;
}
else
{
P.Response.Write(“<Script Language=”JavaScript”>n<!–n alert(“上传文件不可能压倒3M,请选用准确的文件!”)n //–>n</Script>”);
return “”;
}
}
*recipe.doc 文件名以“recipe”结尾且全数“Doc”扩张名的有着文件。
C#文件重命名的代码,
C#中并未有重命名的章程,自个儿写了多个措施,来拍卖文件的重命名。
/// <summary>
/// 重命名文件夹内的全数子文件夹
/// </summary>
/// <param name=”directoryName”>文件夹名称</param>
/// <param name=”newDirectoryName”>新子文件夹名称格式字符串</param>
public void RenameDirectories(string directoryName, string newDirectoryName)
{
int i = 1;
string[] sDirectories = Directory.GetDirectories(directoryName);
foreach (string sDirectory in sDirectories)
{
string sDirectoryName = Path.GetFileName(sDirectory);
string sNewDirectoryName = string.Format(newDirectoryName, i++);
string sNewDirectory = Path.Combine(directoryName, sNewDirectoryName);
Directory.Move(sDirectory, sNewDirectory);
}
}
// 列表中的原始文件全路线名
string oldStr = ft.FileRoute + @”/” + ft.FileName +
ft.ExName;
// 新文件名
string newStr = ft.FileRoute + @”/” + preChar + name +
nextChar + ft.ExName;
// 改名方法
FileInfo fi = new FileInfo(oldStr);
fi.MoveTo(Path.Combine(newStr));
C#中绝非重命名的措施,本人写了三个措施,来管理文件的重命名。 ///summary
/// 重命名文件夹内的全体子文件夹 //…
//
语法:
LastAccess
文件或文件夹上次开发的光阴、
–>
钦点要重命名的文本或文件集的岗位和称号。文件名能够包括通配符(*和?)。
NotifyFilter
获取或安装监视的退换项目。
rename
[<Drive>:][<Path>]<FileName1>
<FileName2>
using
System.IO;
namespace FileSystemWatcherDemo
{
public partial class Form1
: Form
{
public Form1()
{
InitializeComponent();
UsingFileSystemWatcher();
}
www.301.net,///<summary>
/// 使用FileSystemWatcher方法
///</summary>
void
UsingFileSystemWatcher()
{
//6.2
//FileSystemWatcher:侦听文件系统改革文告,并在目录或目录中的文件发出更动时引发风云。
//获取或安装要监视的目录的路线。
fswWatcher.Path
=@”D:upload”;
//获取或设置要监视的改动项目。
fswWatcher.NotifyFilter
= NotifyFilters.LastWrite|NotifyFilters.FileName|NotifyFilters.LastAccess ;
//获取或设置筛选字符串,用于鲜明在目录中监视哪些文件。
//此處只可以監控某后生可畏種文件,不能够監控件多種文书,但能够監控全数文件
fswWatcher.Filter
=”*.doc”;
//获取或安装三个值,该值提示是或不是监视钦点路径中的子目录。
fswWatcher.IncludeSubdirectories =true;
#region 6.3 觸發的事件
//文件或目錄創建時事件
fswWatcher.Created
+=new
FileSystemEventHandler(fswWatcher_Created);
//文件或目錄變更時事件
fswWatcher.Changed
+=new
FileSystemEventHandler(fswWatcher_Changed);
//文件或目錄重命名時事件
fswWatcher.Renamed
+=new
RenamedEventHandler(fswWatcher_Renamed);
//文件或目錄刪除時事件
fswWatcher.Deleted
+=new
FileSystemEventHandler(fswWatcher_Deleted);
#endregion
//获取或设置多个值,该值提示是还是不是启用此组件。
fswWatcher.EnableRaisingEvents =true;
}
#region 6.4 觸發事件的办法
///<summary>
/// 文件或目錄創建時事件措施
///</summary>
///<param
name=”sender”></param>
///<param name=”e”></param>
void
fswWatcher_Created(object
sender, FileSystemEventArgs e)
{
MessageBox.Show(“有新文件”卡塔尔(قطر;
}
///<summary>
/// 文件或目錄變更時事件的情势
///</summary>
///<param
name=”sender”></param>
///<param name=”e”></param>
void
fswWatcher_Changed(object
sender, FileSystemEventArgs e)
{
}
///<summary>
/// 文件或目錄重命名時事件的办法
///</summary>
///<param
name=”sender”></param>
///<param name=”e”></param>
void
fswWatcher_Renamed(object
sender, RenamedEventArgs e)
{
}
///<summary>
/// 文件或目錄刪除時事件的主意
///</summary>
///<param
name=”sender”></param>
///<param name=”e”></param>
void
fswWatcher_Deleted(object
sender, FileSystemEventArgs e)
{
}
#endregion
}
}
4、FileSystemWatcher中Filter屬性通配符說明
筛选字串 监视下列文件
–> 文件名必得是唯大器晚成的文本名。
Security
文件或文件夹的平安设置。
Path
获取或安装监视的目录路线。
Rename 命令:
5、FileSystemWatcher中NotifyFilter枚舉值說明
成员名称 表达
//
参数:
名称 说明
重命名文件或目录。
win*.xml 文件名以“win”开首且具有“xml”扩大名的享有文件。
Sales*200?.xls 相配下列文件:
相关文章
- Linux read语法及深入分析
- 微软:想在WinBlue中还原起来开关?大家听见了 – Windows7之家,Win7之家
- 微软发表Win7授权许可销量达6.3亿份 – Windows7之家,Win7之家
- www.301.net有戏否?微软挺而走险押宝Win8 – Windows7之家,Win7之家
- win10优化开机进度
- windows下批量杀死进程
- 安装Window 10系统——Computer经验
- www.301.netASUSWin8变形本Aspire PAJERO7真机上手图册 – Windows7之家,Win7之家
- 收会员费培养训练黑客并提供工具,法国首都意气风发老黑客入狱 – Windows7之家,Win7之家
- www.301.netEd Bott:Win7是不是现在就能够公布了? – Windows7之家,Win7之家