本来上传是正常的,不知道为什么,今天发现报异常了。处理发生错误!原因:System.IO.FileNotFoundException: Winter.jpg 在 System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) 在 System.Drawing.Image.FromFile(String filename) 在 Manger_imagegallery.UploadImage_OnClick(Object sender, EventArgs e) 位置 d:\wo\Wyweb\Manage\imagery.aspx.cs:行号 106代码是没有问题的,因为我在另外一台电脑运行正常。
奇怪了。 protected void UploadImage_OnClick(object sender, EventArgs e)
{
try
{
this.labIamge.Visible = true;
labIamge.Text = "";
if (imageUpload.PostedFile.FileName == "")
{
Response.Write(ccObj.MessageBox( "要上传的文件不允许为空!"));
return;
}
else
{
string filePath= imageUpload.PostedFile.FileName;
string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1);//图片文件名
string fileEx = filePath.Substring(filePath.LastIndexOf(".") + 1);//扩展名
string serverpath = Server.MapPath(@"~\Images\ftp\") + filename;
string relativepath = @"~\images\ftp\" + filename;
string strSql = "select * from tb_Image where ImageName='"+filename+"'";
DataTable dsTable = SqlBase.Select(strSql);
if (dsTable.Rows.Count > 0)
{
Response.Write(ccObj.MessageBox("该图片已存在!"));
}
else
{
//判断图片格式
if (fileEx == "jpg" || fileEx == "bmp" || fileEx == "gif")
{
//生成缩略图
System.Drawing.Image image, newimage;
image = System.Drawing.Image.FromFile(filePath);
System.Drawing.Image.GetThumbnailImageAbort callb=null;
newimage = image.GetThumbnailImage(67, 90, callb, new System.IntPtr());
//把缩略图保存到指定的虚拟路径
newimage.Save(serverpath);
//释放image对象占用的资源
newimage.Dispose();
image.Dispose();
string strAddSql = "insert into tb_Image(ImageName,ImageUrl)";
strAddSql += "Values('" + filename + "','" + relativepath + "')";
SqlBase.ExecuteSql2(strAddSql);
dlImageBind();
Response.Write(ccObj.MessageBox("上传成功!"));
}
else
{
Response.Write(ccObj.MessageBox("上传的图片扩展名错误!")); }
}
}
}
catch (Exception error)
{
labIamge.Text = "处理发生错误!原因:" + error.ToString();
}
用断点查出是image = System.Drawing.Image.FromFile(filePath);
System.Drawing.Image.GetThumbnailImageAbort callb=null;
没有运行,应该是找不到路径,但问题是,前两天还用的好好的,不知道哪位高手有什么
方法处理,或者说有另外一种写法,稳定点的。
奇怪了。 protected void UploadImage_OnClick(object sender, EventArgs e)
{
try
{
this.labIamge.Visible = true;
labIamge.Text = "";
if (imageUpload.PostedFile.FileName == "")
{
Response.Write(ccObj.MessageBox( "要上传的文件不允许为空!"));
return;
}
else
{
string filePath= imageUpload.PostedFile.FileName;
string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1);//图片文件名
string fileEx = filePath.Substring(filePath.LastIndexOf(".") + 1);//扩展名
string serverpath = Server.MapPath(@"~\Images\ftp\") + filename;
string relativepath = @"~\images\ftp\" + filename;
string strSql = "select * from tb_Image where ImageName='"+filename+"'";
DataTable dsTable = SqlBase.Select(strSql);
if (dsTable.Rows.Count > 0)
{
Response.Write(ccObj.MessageBox("该图片已存在!"));
}
else
{
//判断图片格式
if (fileEx == "jpg" || fileEx == "bmp" || fileEx == "gif")
{
//生成缩略图
System.Drawing.Image image, newimage;
image = System.Drawing.Image.FromFile(filePath);
System.Drawing.Image.GetThumbnailImageAbort callb=null;
newimage = image.GetThumbnailImage(67, 90, callb, new System.IntPtr());
//把缩略图保存到指定的虚拟路径
newimage.Save(serverpath);
//释放image对象占用的资源
newimage.Dispose();
image.Dispose();
string strAddSql = "insert into tb_Image(ImageName,ImageUrl)";
strAddSql += "Values('" + filename + "','" + relativepath + "')";
SqlBase.ExecuteSql2(strAddSql);
dlImageBind();
Response.Write(ccObj.MessageBox("上传成功!"));
}
else
{
Response.Write(ccObj.MessageBox("上传的图片扩展名错误!")); }
}
}
}
catch (Exception error)
{
labIamge.Text = "处理发生错误!原因:" + error.ToString();
}
用断点查出是image = System.Drawing.Image.FromFile(filePath);
System.Drawing.Image.GetThumbnailImageAbort callb=null;
没有运行,应该是找不到路径,但问题是,前两天还用的好好的,不知道哪位高手有什么
方法处理,或者说有另外一种写法,稳定点的。
filePath=serverpath