C#初学者使用file.creat()创建文件后,显示正由另一进程使用
string sourcePhotoPath = this.GetUserSelectedPhoto();
if(sourcePhotoPath == null)
{
return;
}
string sourceFileName = System.IO.Path.GetFileName(sourcePhotoPath);
//把图片保存到文件夹
string userName = this.LoginUserName;
string newPath = @"Images";
if(!System.IO.Directory.Exists(newPath))
{
System.IO.Directory.CreateDirectory(newPath);
}
string destFile = userName + DateTime.Now.ToString("yyyyMMddHHMMss") + "_" + sourceFileName;
string destImgPath = System.IO.Path.Combine(newPath, destFile);
if(!File.Exists(destImgPath))
{
var myFile = File.Create(destImgPath);
myFile.Close();
}
FileInfo f1 = new FileInfo(sourcePhotoPath);
f1.CopyTo(destImgPath,true);
作者:RichardCui
出处:https://www.cnblogs.com/yachao1120/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。该文章也同时发布在我的独立博客中-RichardCuiBlog。

浙公网安备 33010602011771号