路径和权限问题,以下代码可供参考:
string pathfile = upImg.PostedFile.FileName;
string type =
pathfile.Substring(pathfile.LastIndexOf(".") + 1);
string filename =
System.DateTime.Now.ToString("yyMMddhhmmssff") + (".") + type;
if (type == "jpg" || type == "JPG" || type == "png")
{
if (upImg.PostedFile.ContentLength > 1024 * 1024)
{
Page.RegisterStartupScript("js",
"alert('图片过大!')");
}
else
{
try
{
byte[] filedata = new
byte[upImg.PostedFile.ContentLength];
Stream stream =
upImg.PostedFile.InputStream;
stream.Read(filedata, 0,
upImg.PostedFile.ContentLength);
stream.Close();
imgService.imgService services = new
imgService.imgService();
services.Url =
System.Configuration.ConfigurationManager.AppSettings["imgServic
e.imgService"];
services.uploadBrandImage(filedata,
txtBrandNo.Text, filename);
Image1.ImageUrl =
System.Configuration.ConfigurationSettings.AppSettings["ImgUrl"]
+ "/getbrandimage.ashx?brand_No=" + txtBrandNo.Text.ToString() +
"&width=60&height=80";
//Page.RegisterStartupScript("js",
"alert('上传成功!')");
}
catch
{
Page.RegisterStartupScript("js",
"alert('上传失败!')");
}
}
}
else
{
Page.RegisterStartupScript("js", "alert('上
传图片格式不正确!')");
}
}