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

  

posted @ 2018-10-19 13:21  小猫钓鱼吃鱼  阅读(644)  评论(0编辑  收藏  举报