标题:上传图片到文件夹时出错
取消只看楼主
sss333
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-5-16
 问题点数:0 回复次数:0 
上传图片到文件夹时出错

protected void Button1_Click(object sender, EventArgs e)
{
string ext = null, path = null, newFileName = null;
System.Drawing.Image image, newImage;
if (FileUpload1.PostedFile.FileName != null && FileUpload1.PostedFile.FileName != "")
{

//载入原图
image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
//回调
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(callBack);
//生成缩略图
newImage = image.GetThumbnailImage(image.Width / 3, image.Height / 3, callb, new System.IntPtr());
image.Dispose();
newImage.Dispose();

if (FileUpload1.PostedFile != null)
{
//判断是不是图像文件
if (FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
{
Response.Write("文件类型错误");//文件类型错误
}
else
{
ext = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf("."));
//生成新的原文件名 年月日+文件大小+扩展名
path = "upload/" + System.DateTime.Now.Date.ToShortDateString() + FileUpload1.PostedFile.ContentLength.ToString() + ext;

//缩略图文件名
newFileName = "upload/" + System.DateTime.Now.Date.ToShortDateString() + FileUpload1.PostedFile.ContentLength.ToString() + "small" + ext;
//上传缩略图
Bitmap output = new Bitmap(newImage);
//Graphics g = Graphics.FromImage(output);
//output.Save(Server.MapPath(newFileName));
output.save(newFileName);

//FileUpload1.PostedFile.SaveAs(Server.MapPath(newFileName));
FileUpload1.PostedFile.SaveAs(Server.MapPath(path));
}
}
}
else
{
path = null;
newFileName = null;

}
}
标记的那句话有错,应该怎么改呀?大家帮帮忙!谢谢!

搜索更多相关主题的帖子: Drawing null 文件 Image System 
2007-05-16 16:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-139909-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037401 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved