/// <summary>
/// This function changes the file's extension name 
/// which already has the extension name "xml","xsl","in" and "fpr"
/// </summary>
/// <param name="file">The file</param>
/// <returns>Return the changed file</returns>
private FileInfo SwitchExtension(ref FileInfo file)
{
//Get the file's extension and covert it to lower character
string extension = file.Extension.ToLower(); //Change the extension name of the file whose extension name is
//"xml","xsl","in" and "fpr".
//Just adds the "s" character to the head of the extension name
switch (extension)
{
case ".xml":
extension = ".SXML";
break;
case ".xsl":
extension = ".SXSL";
break;
case ".in":
extension = ".SIN";
break;
case ".fpr":
extension = ".SFPR";
break;
}
return file;
}这个原代码肯定有问题,我想用File.Extension = ".sxml",但是Extension是只读的,请教!谢谢。

解决方案 »

  1.   

    File.Move(@"C:\abc.txt",@"C:\abc.dat");
      

  2.   

    (個人想法)是不是可以通過類似于Copy的方法copy(aaa.xml,aaa.SXML);
      

  3.   


    File.Move(旧文件路径,新文件路径)eg:
    File.Move("C:\1.in","C:\1.sin")
      

  4.   

    文件名我是不知道的,我对一个文件夹里的所有文件加密,如果后缀名是.xml、.xsl、.in的就在后缀名前加s.
    反正格式是用-SwitchExtension(FileInfo) : FileInfo
      

  5.   

    好像只能用File.Move
    fileinfo.name就是文件名啊?
    你可以得到文件名,然后解析,替换后缀
    在move