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

  

猜你喜欢

转载自www.cnblogs.com/yachao1120/p/9815918.html
今日推荐