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);
C#初学者使用file.creat()创建文件后,显示正由另一进程使用的更多相关文章
- C#使用File.Create()创建文件后资源被占用
由于文件被占用不能读写,所以报错“另一个程序正在使用此文件进程无法访问” 解决方法是在创建文件后立即Dispose掉 File.Create(path).Dispose();
- File.Create创建文件后,需要释放资源
if (!File.Exists(SavePath)) { File.Create(SavePath).Close(); }
- ifrem上传文件后显示
ifrem上传文件后显示 1.上传文件按钮 <a class="btn btn-primary pull-right" id="data-upload&quo ...
- Java中File类创建文件
只需要调用该类的一个方法createNewFile(),但是在实际操作中需要注意一些事项,如判断文件是否存在,以及如何向新建文件中写入数据等. import java.io.*; public cla ...
- C# 文件读写异常“正由另一进程使用,因此该进程无法访问该文件”
最近在对文件进行读写操作时,利用using的方法可还是遇到了异常"文件正由另一进程使用,因此该进程无法访问该文件": public bool WriteUserInfo(strin ...
- sls语法:创建file,创建文件夹
http://blog.kukafei520.net/html/2014/942.html /tmp/aaa.txt: file.managed /tmp/salt_test: file.direct ...
- 如何给你的VS2010添加创建文件后的头注释
修改VS自带的模板 1) 类文件 D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\ ...
- Windows下Java File对象创建文件夹时的一个"坑"
import java.io.File; import java.io.IOException; public class DirCreate { public static void main(St ...
- 如何解决input file 选取相同文件后,change事件不起作用解决方法
两种方法 1.在你的input所属的form表单reset()就可以了! $("#avatorForm")[0].reset(); 2.设置你的input file value值为 ...
随机推荐
- curl命令查看响应时间
curl -w "%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_dow ...
- Hibernate持久化步骤
1. 读取并解析配置文件 Configuration config= new Configuration().configure(); 相当于使用DataSource获取连接前读取DataSour ...
- Qt 学习之路问题
Qt5 cannot include the file QMainWindow add "greaterThan(QT_MAJOR_VERSION, 4): QT += widgets&qu ...
- O(1)复杂度增加和删除和随机取
题目: https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed 非常好的解法: https://disc ...
- hdu5282 最长公共子序列的变形
pid=5282">http://acm.hdu.edu.cn/showproblem.php?pid=5282 Problem Description Xuejiejie loves ...
- Eclipse中项目进行发布到Tomcat中的位置
Eclips配置tomcat默认是发布到.metadate\plugins\目录下的,wtpwebapps.这样在实际的tomcat目录下,就找不到发布的项目.我们可以自己进行设置,在控制栏中找到se ...
- thinkphp5项目--个人博客(二)
thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- springboot shiro配置
导入相关包(这里配合使用Ehcache缓存) <dependency> <groupId>org.apache.shiro</groupId> <artifa ...
- leetcode 新题型----SQL,shell,system design
leetcode 主要是一个针对北美的coder人群找工作的代码练习网站,我在2015年初次接触这个网站的时候,总共只有200多道题目,是一个类似acm 的a题网站.这些年变化越来越大,主要是因为找工 ...
- Lumia 1520 IE mobile window.devicePixelRatio
Lumia 1520 IE11 mobile -> window.devicePixelRatio = 2.217964285714286 Lumia 1520 UAP 环境 -> win ...