⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filedelete.aspx

📁 ASP.net动画教程
💻 ASPX
字号:
<% @ Page Language="C#" %>
<% @ Import Namespace="System.IO" %>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
	//首先判断文件是否存在
	string delFile = Server.MapPath(".")+"\\CreateText.txt";
	if(File.Exists(delFile))
	{
		//建立FileInfo对象,取得指定的文件信息
		FileInfo fi = new FileInfo(delFile);
		DateTime CreateTime = fi.CreationTime;

		Label lblOne = new Label();
		lblOne.Text = delFile + "存在<br>创建时间为:" + CreateTime.ToString() + "<p>";
		plShow.Controls.Add(lblOne);

		try
		{
			//删除文件
			File.Delete(delFile);
			Label lblOk = new Label();
			lblOk.Text = "删除文件"+delFile+"成功";
			plShow.Controls.Add(lblOk);

		}
		catch(Exception ee)
		{
			//捕捉异常
			Label lblFileExists = new Label();
			lblFileExists.Text = "不能删除文件"+delFile+"<br>";
			plShow.Controls.Add(lblFileExists);
		}
	}
	else
	{
		Label lblError = new Label();
		lblError.Text = delFile + "根本就不存在";
		plShow.Controls.Add(lblError);
	}

}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<b>演示文件的删除操作</b><p>
<asp:Panel id="plShow" runat="server" Font-Name="Arial"/>
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -