本文共 2491 字,大约阅读时间需要 8 分钟。
文件夹管理功能 文件夹管理功能
Server-Side Code
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 (string.IsNullOrEmpty(path)) { return; } int action = 0; if (RadioButton1.Checked) { action = 1; // 创建文件夹 } else if (RadioButton2.Checked) { action = 2; // 删除文件夹 } switch (action) { case 1: if (Directory.Exists(path)) { lblTips.Text = "文件夹已存在!"; return; } else { DirectoryInfo dir = Directory.CreateDirectory(path); lblTips.Text = $"创建时间:{dir.CreationTime}父文件夹:{dir.Parent}"; } break; case 2: try { if (Directory.Exists(path)) { Directory.Delete(path); lblTips.Text = "文件夹已删除!"; } else { lblTips.Text = "文件夹不存在!"; } } catch (Exception ex) { lblTips.Text = ex.Message; } break; default: break; } } }}
转载地址:http://ydrm.baihongyu.com/