/// <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. Eddy's picture(prime+克鲁斯卡尔)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  2. Masterha-manager避免自动关闭的方法

    Masterha-manager启动默认是前端启动 在用MHA配置了MySQL高可用集群时,当master挂掉,完成高可用切换后,Masterha-manager会自动关闭,这不是我想要的...... ...

  3. Gridview 多重表头 (一)

    今天看到一个人每个月更新博客,结果七年后改行去卖土特产...感慨良多... 虽然我也想去开餐厅~~ 今天需求里有一个多重表头,感觉比较奇特,特意留下记录,以防我的大脑被艾滋海默攻占~~没有女主的命,不 ...

  4. C# 单例模式(转)

    C#设计模式学习笔记-单例模式 最近在学设计模式,学到创建型模式的时候,碰到单例模式(或叫单件模式),现在整理一下笔记. 在<Design Patterns:Elements of Resuab ...

  5. Android studio教程:[5]活动的生命周期

    想要学好安卓开发,就必须理解安卓软件的生命周期,明白一个活动的创建.启动.停止.暂停.重启和销毁的过程,知道各个阶段会调用什么函数进行处理不同的情况,这里我就通过一个简单的例子让大家明白一个活动的生命 ...

  6. URI--http://zh.wikipedia.org/wiki/%E7%BB%9F%E4%B8%80%E8%B5%84%E6%BA%90%E6%A0%87%E5%BF%97%E7%AC%A6

    维基百科,自由的百科全书     在电脑术语中,统一资源标识符(Uniform Resource Identifier,或URI)是一个用于标识某一互联网资源名称的字符串. 该种标识允许用户对网络中( ...

  7. ComboGrid 行内点击编辑内容

    最近easyui需要在行内编辑选中项,但是编辑的内容出了当前选中列值,还有其他的,比较麻烦, 先看下这段代码 columns: [[ { field: 'GuestID', title: '编号', ...

  8. 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别(跳出iframe方法)

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

  9. hasClass方法 动画方法说明

    $(this).hasClass("selected");判断是否含有selected样式

  10. 一段phpcurl代码

    $header[] = 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-fl ...