专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > ASP.NET

100分求asp.net操作服务器文件夹和文件的示例函数,该怎么处理

发布时间:2011-06-22 17:12:57 文章来源:www.iduyao.cn 采编人员:星星草
100分求asp.net操作服务器文件夹和文件的示例函数
求asp.net操作服务器文件夹和文件的示例函数

最好送上文件操作类,谢谢,学习中。
最好包括新建、修改、删除、移动文件夹和文件
100分送上


------解决方案--------------------
命名空间System.IO下,很简单
如System.IO.Directory.CreateDirectory(Path)创建目录
System.IO.File.Copy(SourcePath, DestFile)复制一个文件
------解决方案--------------------
搜一下,源码多的惊人!!
------解决方案--------------------
楼主扔个邮箱来,我给你发去
------解决方案--------------------
创建并删除指定的目录和子目录
C# code

using System;
using System.IO;

class Test 
{
    
    public static void Main() 
    {
        string path = @"c:\MyDir";
        string subPath = @"c:\MyDir\temp";

        try 
        {
            // 判断当前路径文件夹是否存在
            if (!Directory.Exists(path)) 
            {
                // 创建路径文件夹.
                Directory.CreateDirectory(path);
            }

            // 判断当前路径文件夹是否存在

            if (!Directory.Exists(subPath)) 
            {
                // 创建路径文件夹.
                Directory.CreateDirectory(subPath);
            }

            // 创建成功.
            Console.WriteLine("I am about to attempt to delete {0}", path);
            //删除文件夹.
            Directory.Delete(path, true);
            Console.WriteLine("The Delete operation was successful.");

        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        } 
        finally {}
    }
}

------解决方案--------------------
移动文件
C# code

System.IO.Directory.Move(要移动的文件或目录的路径, 新位置的路径);

------解决方案--------------------
Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录

/// <summary>
/// 创建文件夹
/// </summary>
/// <param name="Path"></param>
public static void FolderCreate(string Path)
{
// 判断目标目录是否存在如果不存在则新建之
if (!Directory.Exists(Path))
Directory.CreateDirectory(Path);

#endregion

#region 创建目录
public static void FileCreate(string Path)
{
FileInfo CreateFile = new FileInfo(Path); //创建文件 
if (!CreateFile.Exists)
{
FileStream FS = CreateFile.Create();
FS.Close();
}
}
#endregion

#region 递归删除文件夹目录及文件
/****************************************
* 函数名称:DeleteFolder
* 功能说明:递归删除文件夹目录及文件
* 参 数:dir:文件夹路径
* 调用示列:
* string dir = Server.MapPath("test/"); 
* EC.FileObj.DeleteFolder(dir);
*****************************************/
/// <summary>
/// 递归删除文件夹目录及文件
/// </summary>
/// <param name="dir"></param> 
/// <returns></returns>
public static void DeleteFolder(string dir)
{
if (Directory.Exists(dir)) //如果存在这个文件夹删除之 
{
foreach (string d in Directory.GetFileSystemEntries(dir))
{
if (File.Exists(d))
File.Delete(d); //直接删除其中的文件
else
DeleteFolder(d); //递归删除子文件夹 
}
Directory.Delete(dir, true); //删除已空文件夹
}
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: