/// <summary>
/// 创建新文件
/// </summary>
/// <param name="parentPath">文件路径</param>
/// <param name="FileName">文件名称</param>
public void AddFile(string parentPath, string FileName)
{
parentPath = Server.MapPath(parentPath);
bool flag = !Directory.Exists(parentPath + FileName);
if (!flag)
{
HttpContext.Current.Response.Write("<script>alert('该文件以存在');history.go(-1);</script>\uFFFD");
HttpContext.Current.Response.End();
}
else
{
Directory.CreateDirectory(parentPath + FileName);
}
}
/// <summary>
/// 删除文件
/// </summary>
/// <param name="fileName">文件路径</param>
/// <param name="fileType">文件类型</param>
public void Delete(string fileurl, string fileType)
{
bool flag = fileType != "file";//判断文件的类型 file为文件 folder 为文件夹
if (!flag)
{//删除文件
flag = File.Exists(fileurl);
if (flag)
{
File.Delete(fileurl);
}
}
else
{//删除文件夹
flag = Directory.Exists(fileurl);
if (flag)
{
DirectoryInfo directoryInfo = new DirectoryInfo(fileurl);
flag = (directoryInfo.GetDirectories().Length <= 0) && (directoryInfo.GetFiles().Length <= 0);
if (!flag)
{
HttpContext.Current.Response.Write("<script>alert('请先删除文件的子文件');history.go(-1);</script>");
HttpContext.Current.Response.End();
}
else
{
Directory.Delete(fileurl);
}
}
}
}
/// <summary>
/// 获得指定文件的文件内容
/// </summary>
/// <param name="parentPath">相对路径</param>
/// <returns></returns>
public DataSet GetFileList(string parentPath)
{
DataRow row;
string filePath = parentPath;
DataSet set = new DataSet();
DataTable table = new DataTable();
table.Columns.Add("FileType");//指定文件类型 folder 为文件夹
table.Columns.Add("FileName");//文件名称
table.Columns.Add("FileIcon");//文件的图标
table.Columns.Add("FileUrl");//文件的相对路径+文件名称
table.Columns.Add("FilePath");//文件的相对路径
table.Columns.Add("FileSize");//文件大小
table.Columns.Add("FileUrlType");//文件的相对路径+文件名称+类型
DirectoryInfo info = new DirectoryInfo(HttpContext.Current.Server.MapPath(filePath));
foreach (DirectoryInfo info2 in info.GetDirectories())
{//调取文件夹
row = table.NewRow();
row["FileType"] = "folder";
row["FileName"] = info2.Name;
row["FileIcon"] = "<img src=\"Images/closedfolder.gif\" border=\"0\" />";
row["FileUrl"] = filePath + "/" + info2.Name;
row["FilePath"] = filePath;
row["FileSize"] = "";
row["FileUrlType"] = filePath + "/" + info2.Name + ";" + "folder";
table.Rows.Add(row);
}
foreach (FileInfo info3 in info.GetFiles())
{//调取文件
row = table.NewRow();
row["FileType"] = "file";
row["FileName"] = info3.Name;
row["FileIcon"] = "<img src=\"Images/FileIcon/.gif\" class=\"itemimg\" />";//根据扩展名获得Icon
row["FileUrl"] = filePath + "/" + info3.Name;
row["FilePath"] = filePath;
row["FileSize"] = (info3.Length / 0x3e8L) + "K";
row["FileUrlType"] = filePath + "/" + info3.Name + ";" + "file";
table.Rows.Add(row);
}
set.Tables.Add(table);
return set; }

C# Web对文件的管理的更多相关文章

  1. 在Web.Config文件中使用configSource,避免动态修改web.config导致asp.net重启(另添加一个Config文件用于管理用户数据)

    原文:在Web.Config文件中使用configSource,避免动态修改web.config导致asp.net重启(另添加一个Config文件用于管理用户数据) 我们都知道,在asp.net中修改 ...

  2. #WEB安全基础 : HTML/CSS | 0x3文件夹管理网站

    没有头脑的管理方式会酿成大灾难,应该使用文件夹管理网站 这是一个典型的管理方法,现在传授给你,听好了 下面是0x3初识a标签里使用的网站的目录,我把它重新配置了一下

  3. ASP.NET Web API 文件產生器 - 使用 Swagger

    转帖:http://kevintsengtw.blogspot.hk/2015/12/aspnet-web-api-swagger.html Swagger 是一套 API 互動文件產生器,使用 HT ...

  4. .net中Web.config文件的基本原理及相关设置

    11.7  使用web.config配置文件 Web配置文件web.config是Web 应用程序的数据设定文件,它是一份 XML 文件,内含 Web 应用程序相关设定的 XML 标记,可以用来简化  ...

  5. HTTP 错误 500.19 – Internal Server Error web.config 文件的 system.webServer/httpErrors 节中不允许绝对物理路径“C:\inetpub\custerr”[转]

    给ASP或者ASP.NET等需要配置IIS服务器的过程中,很可能会遇到以下两种错误.尤其是用Win7系统的,配置IIS7.0版本比用XP系统配置IIS5.1版本而言要复杂复杂一些.当同时需要配置ASP ...

  6. 容器加載Web工程的Web.xml文件介紹

    转 容器加載Web工程的Web.xml文件介紹 [-] 这篇文章主要是综合网上关于webxml的一些介绍希望对大家有所帮助也欢迎大家一起讨论 ---题记 一            Webxml详解 一 ...

  7. web大文件上传(web应用---SSH框架)

    版权所有 2009-2018荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webapp/up6.2/in ...

  8. Spring整合Hibernate的XML文件配置,以及web.xml文件配置

    利用Spring整合Hibernate时的XML文件配置 applicationContext.xml <?xml version="1.0" encoding=" ...

  9. 七牛云存储的 Javascript Web 前端文件上传

    因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,七牛云存储的 Web 前端文件上传 七牛是不错的云存储产品,特别是有免费的配额可 ...

随机推荐

  1. JsonKit 解析

    - (void)requestMapListData { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"&qu ...

  2. 本人对于JavaScript的一些总结

    类型.值和变量 1.原始类型   数字.字符串和布尔   null空  undefined未定义 2.对象类型 3.类  Array  Function Date RegExp  Error 4.js ...

  3. 【剑指Offer学习】【面试题60:把二叉树打印出多行】

    题目:从上到下按层打印二叉树,同一层的结点按从左到右的顺序打印,每一层打印一行. 解题思路 用一个队列来保存将要打印的结点.为了把二叉树的每一行单独打印到一行里,我们须要两个变量:一个变量表示在当前的 ...

  4. 关于MAC的pkg和mpkg的分别

    程序制作完毕后,在mac下通常的方法是要制作一个pkg的安装包,可是你会发现pkg和mpkg的文件出现的比較多,笔者也是经过了一定的试验和尝试,才了解到,pkg是单个文件的pkg,而mpkg事实上是多 ...

  5. VS2010+ICE3.5运行官方demo报错----std::bad_alloc

    纠结了一晚上,在release版本下运行没问题,一到debug就报错,卡在 Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWith ...

  6. 几种基于javaI/O的文件拷贝操作比较

    最近公司的项目用到文件拷贝,由于涉及到的大量大文件的拷贝工作,代码性能问题显得尤为重要,所以写了以下例子对几种文件拷贝操作做一比较: 0.文件拷贝测试方法 public static void fil ...

  7. nginx错误日志级别

    在配置nginx.conf 的时候,有一项是指定错误日志的,默认情况下你不指定也没有关系,因为nginx很少有错误日志记录的.但有时出现问题时,是有必要记录一下错误日志的,方便我们排查问题.error ...

  8. wamp安装

    下载之后双击文件进行安装选择:I accept the agreement ,点击Next. 一直单击NEXT 安装完成后运行wamp,在桌面右下角即会出现wamp的图标,图标最初是红色的,然后变为橙 ...

  9. canvas入门

    <html> <head> <script> window.onload=function(){ var canvas=document.getElementByI ...

  10. VB.NET Shared(共享)和 Static(静态)关键字的区别

    共享成员(Shared): VB.NET现在是支持真正的面向对象编程,可以继承.使用多态.共享成员 和静态成员. 共享成员就是在所有类和所定义派生类的实例之间共享的方法.属 性.字段和事件.所有使用类 ...