C#初学者使用file.creat()创建文件后,显示正由另一进程使用

时间:2018-03-08 11:47:56   收藏:0   阅读:260

从一个目录选择一个文件,复制到另一个目录

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

 

原文:https://www.cnblogs.com/dotnetHui/p/8527152.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!