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()创建文件后,显示正由另一进程使用的更多相关文章

  1. C#使用File.Create()创建文件后资源被占用

    由于文件被占用不能读写,所以报错“另一个程序正在使用此文件进程无法访问” 解决方法是在创建文件后立即Dispose掉 File.Create(path).Dispose();

  2. File.Create创建文件后,需要释放资源

    if (!File.Exists(SavePath)) { File.Create(SavePath).Close(); }

  3. ifrem上传文件后显示

    ifrem上传文件后显示 1.上传文件按钮    <a class="btn btn-primary pull-right" id="data-upload&quo ...

  4. Java中File类创建文件

    只需要调用该类的一个方法createNewFile(),但是在实际操作中需要注意一些事项,如判断文件是否存在,以及如何向新建文件中写入数据等. import java.io.*; public cla ...

  5. C# 文件读写异常“正由另一进程使用,因此该进程无法访问该文件”

    最近在对文件进行读写操作时,利用using的方法可还是遇到了异常"文件正由另一进程使用,因此该进程无法访问该文件": public bool WriteUserInfo(strin ...

  6. sls语法:创建file,创建文件夹

    http://blog.kukafei520.net/html/2014/942.html /tmp/aaa.txt: file.managed /tmp/salt_test: file.direct ...

  7. 如何给你的VS2010添加创建文件后的头注释

    修改VS自带的模板 1) 类文件 D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\ ...

  8. Windows下Java File对象创建文件夹时的一个"坑"

    import java.io.File; import java.io.IOException; public class DirCreate { public static void main(St ...

  9. 如何解决input file 选取相同文件后,change事件不起作用解决方法

    两种方法 1.在你的input所属的form表单reset()就可以了! $("#avatorForm")[0].reset(); 2.设置你的input file value值为 ...

随机推荐

  1. Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程

    2.Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程 2014-12-07 23:39 2623人阅读 评论(0) ...

  2. 在Windows上面安装多个Memcached

    在Windows上面安装多个Memcached sc create "memcached Server3" start= auto binPath= "D:\memcac ...

  3. ios xcode真机调试获取屏幕截屏

    非常多时候我们须要在调试的过程中把手机屏幕截图发给其它人看,在android开发中我们能够非常方便的截图保存.而xcode开发ios的时候发现这个需求却如此困难.网上大部分都是介绍的以下这个方案.可是 ...

  4. 44.AngularJS Bootstrap

    转自:https://www.cnblogs.com/best/tag/Angular/ Bootstrap 你可以在你的 AngularJS 应用中加入 Twitter Bootstrap,你可以在 ...

  5. Android框架-Volley(四)

    经过前三篇文章的学习,Volley的用法我们已经掌握的差不多了,但是对于Volley的工作原理,恐怕有很多朋友还不是很清楚.因此,本篇文章中我们就来一起阅读一下Volley的源码,将它的工作流程整体地 ...

  6. ACM-ICPC 2017 Asia Urumqi(第八场)

    A. Coins Alice and Bob are playing a simple game. They line up a row of nnn identical coins, all wit ...

  7. @property 的本质是什么?

    将访问.变量.访问控制进行了绑定:编译器负责自动合成. @dynamic:不会自动合成成员变量和存取方法. @property 的本质是什么?@property = ivar + getter + s ...

  8. Kubernetes1.5 集成dashboard

    Kubernetes1.5 集成dashboard 配置kubernetes的dashboard相对简单.同样的,只需要从源码中获取到dashboard-controller.yaml及dashboa ...

  9. jquery validate验证规则重用

    当多个控件验证规则相同时,如何避免冗余代码并应用相同规则呢? [1st way. addMethod+addClassRules] 场景:维护学生档案时需要维护父母.监护人.紧急联系人的身份证号码,此 ...

  10. iOS下调用元素的focus方法,input元素不聚焦,键盘不弹起的问题

    页面元素 <input type="text" ref="elInput"/> <div style="margin-top:20p ...