比如我上传一个文件为 aaa.xls但是我想把aaa名字给替换掉,代码怎么写啊,? HttpPostedFile hpf = FileUpload2.PostedFile;
 FileInfo FI = new FileInfo(FileUpload2.PostedFile.FileName); 
 
写到这里,我不晓得怎么办了?

解决方案 »

  1.   

    System.IO.File.Move(server.MapPath("相对路径"), "新文件名");   
      

  2.   


    string path = Server.MapPath("~/User/photo/");
    string filename = FileUpload1.FileName;
    int index = filename.LastIndexOf(".");
    string lastName = filename.Substring(index, filename.Length - index);//文件的后缀名
    string newfile = "新名字" + lastName;  //组合新名字
    FileUpload1.PostedFile.SaveAs(path + newfile); //保存
      

  3.   

     //得到要上传文件
                HttpPostedFile postedFile = context;            //文件名称
                string fileName = System.IO.Path.GetFileName(postedFile.FileName);            //上传文件的扩展名
                string fileExtension = System.IO.Path.GetExtension(fileName);            //给文件重新命名
                string new_filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + fileExtension;