在server.mappath文件夹中C#上传图片更新....? [英] C# upload image update in server.mappath folder ....?
本文介绍了在server.mappath文件夹中C#上传图片更新....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们,
i我试图更新学生个人资料图片一旦我更新照片我得到一个错误,我有如下所示。请告诉我们有没有人知道
错误:
hi friends,
i am trying to update student profile picture once i update the photo i am getting one Error which i have showed below. please tell me guys if anyone knows
Error:"
The process cannot access the file '1.png' because it is being used by another process.
这个错误而不是
"
for this Error Instead of
var directory = new DirectoryInfo(path);
directory.Delete(true);
此行我使用
Directory.Delete(path);
但是agin我得到错误像
错误:
but agin i am getting Error like
Error:
The directory is not empty.
我的尝试:
What I have tried:
public static string ImageToServerPath(student[] student)
{
DataImage image = DataImage.TryParse(student[0].path);
MemoryStream ms = new MemoryStream(image.RawData);
Bitmap BMP = new Bitmap(image.Image);
string configPath = WebConfigurationManager.AppSettings["Path"];
string path =configPath+""+student[0].studentId+"\\";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
else
{
Directory.Delete(path);
Directory.CreateDirectory(path);
}
FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, path);
if (SecurityManager.IsGranted(writePermission))
{
int imagename = 1;
System.Drawing.Image img = new System.Drawing.Bitmap(ms);
img.Save(path + student[0].studentId + ".png", ImageFormat.Png);
path = path + "" + imagename + ".png";
}
return path;
}
推荐答案
我认为你需要关闭MemoryStream
使用后:
I think you need to close theMemoryStream
after using it:
using (MemoryStream ms = new MemoryStream(image.RawData);)
{
BMP = new Bitmap(image.Image);
}
我还要看一下:
I would also take a look at:
DataImage image = DataImage.TryParse(student[0].path);
由于我没有你的源代码,我不知道那里发生了什么......
As I don't have your source code, I can not tell what is happening there ...
>
这篇关于在server.mappath文件夹中C#上传图片更新....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文