c# - c#中删除子文件夹
问题描述
我正在为 ASP.NET 中的示例程序创建一个上传页面。现在我将学生文档上传certificates,marksheets
到本地存储中,并将该文件保存在特定目录中。D:\Vinayak\Student\Profiledocs\610\myfile.txt
上传成功。
现在,我正在使用我的 ASP.NET 页面删除本地存储中的特定学生个人资料文档。
D:\Vinayak\Student\Profiledocs\610\myfile.txt
是我的文件存储目录。
现在我如何删除这个子文件夹和文件\610\myfile.txt
。
610
studentid
是我的表中名为 by 的列值student details
。
如果我选择任何学生 ID,610 or 12
无论它是什么。
学生文件保存在我的父文件夹Profiledocs
中。像这样
\Profiledocs\610\myfile.txt
\Profiledocs\121\myfile1.txt
\Profiledocs\321\myfile2.txt
现在我要删除父文件夹中的子文件夹和文件Profiledocs
解决方案
studentId
您可以使用以下方法通过作为参数传递来删除子文件夹及其内容。
private static void DeleteSubFolderAndContent(int studentId)
{
string path = Path.Combine(@"D:\Vinayak\Student\Profiledocs", studentId.ToString());
Directory.Delete(path, true);
}
您可以使用上述功能
static void Main(string[] args)
{
DeleteSubFolderAndContent(610); // <= "610" comes from database
Console.WriteLine("Sub Folder and Its Content Deleted Successfully");
Console.ReadLine();
}
注意:确保您的上传文件夹具有完全的读写权限控制。
推荐阅读
- python - 如何在不使用迭代器和蛮力的情况下在python中查找列表中元素的所有两位数组合
- javascript - 在javascript中打印一个8位字节的二进制补码字符串
- javascript - 如何在 VueJS 中动态提供 API 发送的 pdf 文件?
- php - 保存 PHPSpreadSheet 对象
- python - 使用列表生成嵌套的 json 布局
- c - 对二维数组的每一行的所有最大元素求和
- javascript - 将原型函数添加到特定字符串?
- jax-rs - 使用 CXF 代理客户端时在运行时添加查询参数
- azure-devops - VSTS - 自动链接此版本中的新作品不起作用
- postgresql - 在 PostgreSQL 中使用 COPY FROM 命令在多个表中插入