日期:2011-10-04 浏览次数:20614 次
private void Button1_Click(object sender, System.EventArgs e)
{//新建文件
string path=Server.MapPath("index4.aspx");
//Response.Write(DateTime.Now.ToString("yyyymmdd"));
//获得文件名
int fileLen=path.LastIndexOf(".");
int pathLen=path.Length;
string tempName=path.Substring(fileLen,pathLen-fileLen);
//获取文件路径
int len=path.LastIndexOf(@"\");
string tempPath=path.Substring(0,len)+"\\"+DateTime.Now.ToString("yyyymmddhhssmm")+tempName;
try
{
File.Create(tempPath);
Response.Write("<script>alert('新建文件成功');</script>");
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
private void Button2_Click(object sender, System.EventArgs e)
{//复制文件
string path=Server.MapPath("index4.aspx");
//Response.Write(DateTime.Now.ToString("yyyymmdd"));
//获得文件名
int fileLen=path.LastIndexOf(".");
int pathLen=path.Length;
string tempName=path.Substring(fileLen,pathLen-fileLen);
//获取文件路径
int len=path.LastIndexOf(@"\");
string tempPath=path.Substring(0,len)+"\\"+DateTime.Now.ToString("yyyymmddhhssmm")+tempName;
try
{
File.Copy(path,tempPath);
Response.Write("<script>alert('复制文件成功');</script>");
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
private void Button3_Click(object sender, System.EventArgs e)
{//删除文件
string path=Server.MapPath("index4.aspx");
//Response.Write(DateTime.Now.ToString("yyyymmdd"));
//获得文件名
int fileLen=path.LastIndexOf(".");
int pathLen=path.Length;
string tempName=path.Substring(fileLen,pathLen-fileLen);
//获取文件路径
int len=path.LastIndexOf(@"\");
//string tempPath=path.Substring(0,len)+"\\"+DateTime.Now.ToString("yyyymmddhhssmm")+tempName;
string tempPath=path.Substring(0,len)+"\\"+"20063702021337.aspx";
try
{
File.Delete(tempPath);
Response.Write("<script>alert('删除文件成功');</script>");
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}