c#追加文件
streamwriter sw = file.appendtext(server.mappath(".")+"\\mytext.txt");
sw.writeline("追逐理想");
sw.writeline("kzlll");
sw.writeline(".net笔记");
sw.flush();
sw.close();
c#拷贝文件
string orignfile,newfile;
orignfile = server.mappath(".")+"\\mytext.txt";
newfile = server.mappath(".")+"\\mytextcopy.txt";
file.copy(orignfile,newfile,true);

c#删除文件
string delfile = server.mappath(".")+"\\mytextcopy.txt";
file.delete(delfile);

c#移动文件
string orignfile,newfile;
orignfile = server.mappath(".")+"\\mytext.txt";
newfile = server.mappath(".")+"\\mytextcopy.txt";
file.move(orignfile,newfile);

c#创建目录
// 创建目录c:\sixage
directoryinfo d=directory.createdirectory("c:\\sixage");
// d1指向c:\sixage\sixage1
directoryinfo d1=d.createsubdirectory("sixage1");
// d2指向c:\sixage\sixage1\sixage1_1
directoryinfo d2=d1.createsubdirectory("sixage1_1");
// 将当前目录设为c:\sixage
directory.setcurrentdirectory("c:\\sixage");
// 创建目录c:\sixage\sixage2
directory.createdirectory("sixage2");
// 创建目录c:\sixage\sixage2\sixage2_1
directory.createdirectory("sixage2\\sixage2_1");

递归删除文件夹及文件
<%@ page language=c#%>
<%@ import namespace="system.io"%>
<script runat=server>
public 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); //删除已空文件夹
        response.write(dir+" 文件夹删除成功");
    }
    else
        response.write(dir+" 该文件夹不存在"); //如果文件夹不存在则提示
}

protected void page_load (object sender ,eventargs e)
{
    string dir="d:\\gbook\\11";
    deletefolder(dir); //调用函数删除文件夹
}


// ======================================================
  // 实现一个静态方法将指定文件夹下面的所有内容copy到目标文件夹下面
  // 如果目标文件夹为只读属性就会报错。
  // april 18april2005 in stu
  // ======================================================
  public static void copydir(string srcpath,string aimpath)
  {
   try
   {
    // 检查目标目录是否以目录分割字符结束如果不是则添加之
    if(aimpath[aimpath.length-1] != path.directoryseparatorchar)
     aimpath += path.directoryseparatorchar;
    // 判断目标目录是否存在如果不存在则新建之
    if(!directory.exists(aimpath)) directory.createdirectory(aimpath);
    // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
    // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
    // string[] filelist = directory.getfiles(srcpath);
    string[] filelist = directory.getfilesystementries(srcpath);
    // 遍历所有的文件和目录
    foreach(string file in filelist)
    {
     // 先当作目录处理如果存在这个目录就递归copy该目录下面的文件
     if(directory.exists(file))
      copydir(file,aimpath+path.getfilename(file));
      // 否则直接copy文件
     else
      file.copy(file,aimpath+path.getfilename(file),true);
    }
   }
   catch (exception e)
   {
    messagebox.show (e.tostring());
   }
  }

  // ======================================================
  // 实现一个静态方法将指定文件夹下面的所有内容detele
  // 测试的时候要小心操作,删除之后无法恢复。
  // april 18april2005 in stu
  // ======================================================
  public static void deletedir(string aimpath)
  {
   try
   {
    // 检查目标目录是否以目录分割字符结束如果不是则添加之
    if(aimpath[aimpath.length-1] != path.directoryseparatorchar)
     aimpath += path.directoryseparatorchar;
    // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
    // 如果你指向delete目标文件下面的文件而不包含目录请使用下面的方法
    // string[] filelist = directory.getfiles(aimpath);
    string[] filelist = directory.getfilesystementries(aimpath);
    // 遍历所有的文件和目录
    foreach(string file in filelist)
    {
     // 先当作目录处理如果存在这个目录就递归delete该目录下面的文件
     if(directory.exists(file))
     {
      deletedir(aimpath+path.getfilename(file));
     }
      // 否则直接delete文件
     else
     {
      file.delete (aimpath+path.getfilename(file));
     }
    }
    //删除文件夹
    system.io .directory .delete (aimpath,true);
   }
   catch (exception e)
   {
    messagebox.show (e.tostring());
   }
  }

需要引用命名空间:
using system.io;

/**//// <summary>
 
  /// </summary>
  /// <param ></param>
  /// <param ></param>

  //--------------------------------------------------
 //---------------------------------------------------

  public static void copyfolder(string strfrompath,string strtopath)
  {
   //如果源文件夹不存在,则创建
   if (!directory.exists(strfrompath))
   {   
    directory.createdirectory(strfrompath);
   }  

   //取得要拷贝的文件夹名
   string strfoldername = strfrompath.substring(strfrompath.lastindexof("\\") + 1,strfrompath.length - strfrompath.lastindexof("\\") - 1);  

   //如果目标文件夹中没有源文件夹则在目标文件夹中创建源文件夹
   if (!directory.exists(strtopath + "\\" + strfoldername))
   {   
    directory.createdirectory(strtopath + "\\" + strfoldername);
   }
   //创建数组保存源文件夹下的文件名
   string[] strfiles = directory.getfiles(strfrompath);

   //循环拷贝文件
   for(int i = 0;i < strfiles.length;i++)
   {
    //取得拷贝的文件名,只取文件名,地址截掉。
    string strfilename = strfiles[i].substring(strfiles[i].lastindexof("\\") + 1,strfiles[i].length - strfiles[i].lastindexof("\\") - 1);
    //开始拷贝文件,true表示覆盖同名文件
    file.copy(strfiles[i],strtopath + "\\" + strfoldername + "\\" + strfilename,true);
   }
 
   //创建directoryinfo实例
   directoryinfo dirinfo = new directoryinfo(strfrompath);
   //取得源文件夹下的所有子文件夹名称
   directoryinfo[] zipath = dirinfo.getdirectories();
   for (int j = 0;j < zipath.length;j++)
   {
    //获取所有子文件夹名
    string strzipath = strfrompath + "\\" + zipath[j].tostring();  
    //把得到的子文件夹当成新的源文件夹,从头开始新一轮的拷贝
    copyfolder(strzipath,strtopath + "\\" + strfoldername);
   }
  }

一.读取文本文件
1/**//// <summary>
 2/// 读取文本文件
 3/// </summary>
 4private void readfromtxtfile()
 5{
 6    if(filepath.postedfile.filename != "")
 7    {
 8        txtfilepath =filepath.postedfile.filename;
 9        fileextname = txtfilepath.substring(txtfilepath.lastindexof(".")+1,3);
10
11        if(fileextname !="txt" && fileextname != "txt")
12        {
13            response.write("请选择文本文件");
14        }
15        else
16        {
17            streamreader filestream = new streamreader(txtfilepath,encoding.default);
18            txtcontent.text = filestream.readtoend();
19            filestream.close();
20        }
21    }
22 }
二.获取文件列表
1/**//// <summary>
  2/// 获取文件列表
  3/// </summary>
  4private void getfilelist()
  5{
  6    string strcurdir,filename,fileext;
  7   
  8    /**////文件大小
  9    long filesize;
 10   
 11    /**////最后修改时间;
 12    datetime filemodify;
 13
 14    /**////初始化
 15    if(!ispostback)
 16    {
 17        /**////初始化时,默认为当前页面所在的目录
 18        strcurdir = server.mappath(".");
 19        lblcurdir.text = strcurdir;
 20        txtcurdir.text = strcurdir;
 21    }
 22    else
 23    {
 24        strcurdir = txtcurdir.text;
 25        txtcurdir.text = strcurdir;
 26        lblcurdir.text = strcurdir;
 27    }
 28    fileinfo fi;
 29    directoryinfo dir;
 30    tablecell td;
 31    tablerow tr;
 32    tr = new tablerow();
 33   
 34    /**////动态添加单元格内容
 35    td = new tablecell();
 36    td.controls.add(new literalcontrol("文件名"));
 37    tr.cells.add(td);
 38    td = new tablecell();
 39    td.controls.add(new literalcontrol("文件类型"));
 40    tr.cells.add(td);
 41    td = new tablecell();
 42    td.controls.add(new literalcontrol("文件大小"));
 43    tr.cells.add(td);
 44    td = new tablecell();
 45    td.controls.add(new literalcontrol("最后修改时间"));
 46    tr.cells.add(td);
 47
 48    tabledirinfo.rows.add(tr);
 49   
 50    /**////针对当前目录建立目录引用对象
 51    directoryinfo dirinfo = new directoryinfo(txtcurdir.text);
 52   
 53    /**////循环判断当前目录下的文件和目录
 54    foreach(filesysteminfo fsi in dirinfo.getfilesysteminfos())
 55    {
 56        filename = "";
 57        fileext = "";
 58        filesize = 0;
 59       
 60        /**////如果是文件
 61        if(fsi is fileinfo)
 62        {
 63            fi = (fileinfo)fsi;
 64           
 65            /**////取得文件名
 66            filename = fi.name;
 67           
 68            /**////取得文件的扩展名
 69            fileext = fi.extension;
 70           
 71            /**////取得文件的大小
 72            filesize = fi.length;
 73           
 74            /**////取得文件的最后修改时间
 75            filemodify = fi.lastwritetime;
 76        }
 77
 78        /**////否则是目录
 79        else
 80        {
 81            dir = (directoryinfo)fsi;
 82           
 83            /**////取得目录名
 84            filename = dir.name;
 85           
 86            /**////取得目录的最后修改时间
 87            filemodify = dir.lastwritetime;
 88           
 89            /**////设置文件的扩展名为"文件夹"
 90            fileext = "文件夹";
 91        }
 92       
 93        /**////动态添加表格内容
 94        tr = new tablerow();
 95        td = new tablecell();
 96        td.controls.add(new literalcontrol(filename));
 97        tr.cells.add(td);
 98        td = new tablecell();
 99        td.controls.add(new literalcontrol(fileext));
100        tr.cells.add(td);
101        td = new tablecell();
102        td.controls.add(new literalcontrol(filesize.tostring()+"字节"));
103        tr.cells.add(td);
104        td = new tablecell();
105        td.controls.add(new literalcontrol(filemodify.tostring("yyyy-mm-dd hh:mm:ss")));
106        tr.cells.add(td);
107        tabledirinfo.rows.add(tr);
108    }
109}