asp.net如何更改文件名啊
我想把c:\aa.txt
改名成 c:\bb.txt
如何更改,
我在File类中没有找到改文件名的方法

解决方案 »

  1.   

    File.Remove()同时具有移到和改名的功能.
      

  2.   

    还是不行,为什么会出这权错误,我都是用管理员用户做IIS的用户了对路径的访问被拒绝。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.UnauthorizedAccessException: 对路径的访问被拒绝。 ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限。ASP.NET 有一个在应用程序没有模拟时使用的基进程标识(通常,在 IIS 5 上为 {MACHINE}\ASPNET,在 IIS 6 上为网络服务)。如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。 若要授予 ASP.NET 对文件的写访问权,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”添加适当的用户或组。突出显示 ASP.NET 帐户,选中所需访问权限对应的框。源错误: 
    行 124: }
    行 125: }
    行 126: files[i].MoveTo(files[i].FullName + "1");
    行 127: }
    行 128: }
     
      

  3.   

    给ASP.NET 帐户加上写的权限
      

  4.   

    string srcFileName=@"c:\meng\a.txt";
    string destFileName=@"c:\meng\b.txt";string srcFolderPath=@"c:\temp";
    string destFolderPath=@"c:\temp11";
    //方法一 
    if (System.IO.File.Exists(srcFileName)) 

    System.IO.File.Move(srcFileName,destFileName);

    if (System.IO.Directory.Exists(srcFolderPath)) 

    System.IO.Directory.Move(srcFolderPath,destFolderPath);
    }

    //方法二
    if (System.IO.File.Exists(srcFileName)) 

    System.IO.FileInfo file=new System.IO.FileInfo(srcFileName); 
    file.MoveTo(destFileName); 

    if (System.IO.Directory.Exists(srcFolderPath)) 

    System.IO.DirectoryInfo folder=new System.IO.DirectoryInfo(srcFolderPath); 
    folder.MoveTo(destFolderPath); 
    }