本文共 2301 字,大约阅读时间需要 7 分钟。
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test14_8.WebForm1" %>
webform1.aspx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;namespace test14_8{ public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string path = TextBox1.Text; if (path == string.Empty) return; int action = 0; if (RadioButton1.Checked) { action = 1; // 创建 } if (RadioButton2.Checked) { action = 2; //删除 } switch (action) { case 1: if (Directory.Exists(path)) { lblTips.Text = "文件夹已存在!"; return; } else { DirectoryInfo dr = Directory.CreateDirectory(path); lblTips.Text = ""; lblTips.Text += "创建时间:" + dr.CreationTime + ""; lblTips.Text += "父文件夹:" + dr.Parent + ""; } break; case 2: if (Directory.Exists(path)) { try { Directory.Delete(path); lblTips.Text = ""; lblTips.Text = "文件夹已删除!"; } catch (Exception ex) { lblTips.Text = ex.Message; } } else { lblTips.Text = "文件夹不存在!"; } break; default: return; break; } } }}
转载地址:http://ydrm.baihongyu.com/