
asp.net 4.5 练习~test14-2 对文件夹操作
发布日期:2021-05-06 21:16:21
浏览次数:32
分类:精选文章
本文共 3287 字,大约阅读时间需要 10 分钟。
文件夹管理工具
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace test14_2{ public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // 初始化提示信息标签 lblTips.Text = ""; } // 新建文件夹 protected void Button1_Click(object sender, EventArgs e) { try { string folderPath = TextBox1.Text; if (Directory.Exists(folderPath)) { lblTips.Text = "此文件夹已经存在,请重新输入!"; return; } Directory.CreateDirectory(folderPath); lblTips.Text = "文件夹创建成功!"; } catch (Exception error) { lblTips.Text = "创建失败!原因是" + error.Message.ToString(); } } // 移动文件夹 protected void Button2_Click(object sender, EventArgs e) { try { string sourcePath = TextBox2.Text; string targetPath = TextBox3.Text; if (!Directory.Exists(sourcePath)) { lblTips.Text = "源文件夹不存在,无法移动"; return; } if (Directory.Exists(targetPath)) { lblTips.Text = "新文件夹已经存在,无法移动"; return; } Directory.Move(sourcePath, targetPath); lblTips.Text = "文件夹移动成功!"; } catch (Exception ex) { lblTips.Text = "移动失败!原因是" + ex.Message.ToString(); } } // 删除文件夹 protected void Button3_Click(object sender, EventArgs e) { try { string folderPath = TextBox4.Text; if (Directory.Exists(folderPath)) { if (CheckBox1.Checked) { // 删除文件夹及其所有内容 Directory.Delete(folderPath, true); lblTips.Text = "文件夹删除成功!"; } else { // 只删除文件夹本身 Directory.Delete(folderPath); lblTips.Text = "文件夹删除成功!"; } } else { lblTips.Text = "此文件夹不存在!"; } } catch (Exception error) { lblTips.Text = "删除失败!原因是" + error.Message.ToString(); } } }}
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月25日 15时27分21秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
boot.img 解包与打包
2019-03-05
Android4.4 平板背光设置
2019-03-05
spring boot@Value和bean执行顺序问题
2019-03-05
codeforces The Eternal Immortality 题解
2019-03-05
蓝桥杯 历届试题 幸运数 (堆+DFS)
2019-03-05
微信js-sdk使用简述(分享,扫码功能等)
2019-03-05
selenium 的介绍和爬取 jd数据
2019-03-05
【分享-一键在线抠图】在线免费去除图片背景
2019-03-05
layui表格checkbox选择全选样式及功能
2019-03-05
mxsrvs支持thinkphp3.2伪静态
2019-03-05
mui HTML5 plus 下载文件
2019-03-05
环信SDK 踩坑记webIM篇(一)
2019-03-05
通信基础知识
2019-03-05
DSP开发板准备
2019-03-05
测试基本
2019-03-05
c++中istringstream及ostringstream超详细说明
2019-03-05
c++中ifstream及ofstream超详细说明
2019-03-05
c++中explicit和mutable关键字探究
2019-03-05
c语言结构体字节对齐详解
2019-03-05