上传头像 我在做学员上传头像时,想判断上传的头像是否在文件夹已存在,如果存在就删除,可是他总是说此图片正由另一进程使用,因此该进程无法访问该文件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有释放进程,在Using(){}里面写他自己会给你释放进程 if (openFileDialog1.ShowDialog()==DialogResult.OK) { try { openFileDialog1.DefaultExt = "jpg"; openFileDialog1.Filter = "jpeg图片格式(*.jpeg)|(*.jpeg)|jpg图片格式(*.jpg)|*.jpg|gif图片格式(*.gif)|*.gif|bmp图片格式(*.bmp)|*.bmp|psd图片格式(*.psd)|*.psd|png图片格式(*.png)|*.png"; string en = openFileDialog1.SafeFileName.Substring(openFileDialog1.SafeFileName.IndexOf(".")); GetFaceImg(); if (faceUrl != "") { File.Delete(faceUrl); } string url = ""; if (stuType== "update") { url = @"F:\项目开发Vss\头像\" + "imgStu" + SutPk + en;//重新命名 } else if (stuType == "add") { url = @"F:\项目开发Vss\头像\" + "imgStu" + stuID + en;//重新命名 } imgurl = url; if (File.Exists(url)) { isDelete = 0; filename = openFileDialog1.FileName; } else { isDelete = 1; filename = openFileDialog1.FileName; } } catch (Exception ex) { MessageBox.Show(ex.Message) ; } //finally //{ // this.pictureBox1.Image.Dispose(); //} } else { return; } 把什么写到using里面啊拜托说的详细一点谢谢 我已经贴了在上面呢那是选择图片这是保存的部分代码 if (stuType == "update") { if (imgurl != "") { faceUrl = imgurl; } UpdateStuinfo(); this.pictureBox1.Dispose(); if (isDelete == 0) { File.Delete(imgurl); File.Copy(filename, imgurl); } else if (isDelete == 1) { File.Copy(filename, imgurl); } } [向笨虫子爬爬提问] 另一种方法是什么? 更换了端口 WebService 无法连接到远程服务器 DataSet读取数据时,有出错,请帮忙看看! 关于读取远程xml 捆绑GridView的问题 退出程序用哪个方法? C# 数据保存问题 敏感信息 关于asp转C#代码的问题 求助!急!(6) C#窗体连接数据库的问题(新手求教!) 一个有难度的问题,高分求解,请进.. 怎么把有'\0'转换成空格?
{
try
{
openFileDialog1.DefaultExt = "jpg";
openFileDialog1.Filter = "jpeg图片格式(*.jpeg)|(*.jpeg)|jpg图片格式(*.jpg)|*.jpg|gif图片格式(*.gif)|*.gif|bmp图片格式(*.bmp)|*.bmp|psd图片格式(*.psd)|*.psd|png图片格式(*.png)|*.png";
string en = openFileDialog1.SafeFileName.Substring(openFileDialog1.SafeFileName.IndexOf("."));
GetFaceImg();
if (faceUrl != "")
{
File.Delete(faceUrl);
}
string url = "";
if (stuType== "update")
{
url = @"F:\项目开发Vss\头像\" + "imgStu" + SutPk + en;//重新命名
}
else
if (stuType == "add")
{
url = @"F:\项目开发Vss\头像\" + "imgStu" + stuID + en;//重新命名
} imgurl = url;
if (File.Exists(url))
{
isDelete = 0;
filename = openFileDialog1.FileName;
}
else
{
isDelete = 1;
filename = openFileDialog1.FileName;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message) ;
}
//finally
//{
// this.pictureBox1.Image.Dispose();
//}
}
else
{
return;
}
这是保存的部分代码
if (stuType == "update")
{
if (imgurl != "")
{
faceUrl = imgurl;
}
UpdateStuinfo();
this.pictureBox1.Dispose();
if (isDelete == 0)
{
File.Delete(imgurl);
File.Copy(filename, imgurl);
}
else if (isDelete == 1)
{
File.Copy(filename, imgurl);
}
}