/// <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. JS 清除IE缓存

    js中自动清除ie缓存方法 — 常用 对于动态文件,比如 index.asp?id=...  或者 index.aspx?id=... 相信有经验的程序员都知道怎样禁止浏览器缓存数据了.  但是对于静 ...

  2. nginx日志格式

    日志格式 log_format main '$remote_addr - $remote_user [$time_local] $request '                    '" ...

  3. hadoop源码编译

    为何要自行编译hadoop源码,往往是由于官方提供的hadoop发行版都是基于32位操作系统,在操作hadoop时会发生warn.   准备软件: 1)JDK 2)Hadoop源码 3)Maven 4 ...

  4. C - The Hardest Problem Ever

    Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever ...

  5. 微信JS-SDK说明文档及常见问题处理

    概述 微信JS-SDK是微信公众平台面向网页开发者提供的基于微信内的网页开发工具包. 通过使用微信JS-SDK,网页开发者可借助微信高效地使用拍照.选图.语音.位置等手机系统的能力,同时可以直接使用微 ...

  6. oracle 序列

    查询序列值 select td_prodline_attr_seq.nextval from dual     查询用户建的所有序列 用户名 必须大写select SEQUENCE_OWNER,SEQ ...

  7. Android Adapter代码片

    /** * Adapter for grid of coupons. */ private static class CouponAdapter extends BaseAdapter { priva ...

  8. bokeh-scala

    使用bokeh-scala进行数据可视化 目录 前言 bokeh简介及胡扯 bokeh-scala基本代码 我的封装 总结 一.前言 最近在使用spark集群以及geotrellis框架(相关文章见h ...

  9. python 序列类型

    1.不可变的序列类型:tuple.range.str.set 001:对于tuple 类型有如下几种构造方式 1.() 构造一个空的元组. 2.a | (a,) 构造一个只有一个元素的元组. 3.tu ...

  10. Oracle 11gR2 RAC 安装配置

    1. 简介   Oracle RAC,全称real application clusters,译为"实时应用集群", 是Oracle新版数据库中采用的一项新技术,是高可用性的一种, ...