1. 程式人生 > >C#初學者使用file.creat()創建文件後,顯示正由另一進程使用

C#初學者使用file.creat()創建文件後,顯示正由另一進程使用

user div ceph director 圖片保存 sele sys mms login

從一個目錄選擇一個文件,復制到另一個目錄

 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);

C#初學者使用file.creat()創建文件後,顯示正由另一進程使用