从一个目录选择一个文件,复制到另一个目录
1 string sourcePhotoPath = this.GetUserSelectedPhoto(); 2 if(sourcePhotoPath == null) 3 { 4 return; 5 } 6 string sourceFileName = System.IO.Path.GetFileName(sourcePhotoPath); 7 //把图片保存到文件夹 8 string userName = this.LoginUserName; 9 string newPath = @"Images"; 10 if(!System.IO.Directory.Exists(newPath)) 11 { 12 System.IO.Directory.CreateDirectory(newPath); 13 } 14 string destFile = userName + DateTime.Now.ToString("yyyyMMddHHMMss") + "_" + sourceFileName; 15 string destImgPath = System.IO.Path.Combine(newPath, destFile); 16 if(!File.Exists(destImgPath)) 17 { 18 var myFile = File.Create(destImgPath); 19 myFile.Close(); 20 } 21 FileInfo f1 = new FileInfo(sourcePhotoPath); 22 f1.CopyTo(destImgPath,true);