100分求上传图片属性里的大小问题 肯定没有保存成功啊http://dotnet.aspx.cc/ShowDetail.aspx?id=58EA3515-36F2-4FD9-AC89-EAF49F59816C 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 还有这等问题,真的还没碰到过,帮你顶----------------------------------------------------------------------欢迎试用ASP.NET大文件上传组件(AspnetUpload 1.0 Release & 无刷新进度条)http://bestcomy.europe.webmatrixhosting.net---------------------------------------------------------------------- if("" != UpFileControl.PostedFile.FileName) { imagePath= UpFileControl.PostedFile.FileName; imageType= imagePath.Substring(imagePath.LastIndexOf(".")+1); imageName = imagePath.Substring(imagePath.LastIndexOf("\\")+1); if("jpg" != imageType && "gif" != imageType) { Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>"); return; } else { HttpPostedFile SendImage=UpFileControl.PostedFile; imageSize=SendImage.ContentLength;////取得图片 imageBody=new Byte[imageSize]; Stream StreamObject=SendImage.InputStream;//建立数据流对象 StreamObject.Read(imageBody,0,imageSize);///把图像数据放到mMarkBody中,其中0代表数据指针位置,intFileLength代表要读取的流的长度 imagePath=UpFileControl.PostedFile.FileName;//取得图象路径 SqlCom="insert into Image(ImageName,Image,ImageSize) values('"+imageName+"','"+imageBody+"','"+imageSize.ToString()+"')"; con.Open(); cmd = new SqlCommand(SqlCom,con); try { cmd.ExecuteNonQuery(); Response.Write("成功!"); } catch { Response.Write("失败!"); } con.Close(); } } HttpFileCollection files = HttpContext.Current.Request.Files; System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); try { for(int iFile = 0; iFile < files.Count; iFile++) { ///'检查文件扩展名字 HttpPostedFile postedFile = files[iFile]; string fileName, fileExtension; fileName = System.IO.Path.GetFileName(postedFile.FileName); if (fileName != "") { fileExtension = System.IO.Path.GetExtension(fileName); postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName); } } strStatus.Text = strMsg.ToString(); return true; } catch(System.Exception Ex) { strStatus.Text = Ex.Message; return false; } <%@ Page Language="c#" Debug="true" Trace="true"%><%@ Import Namespace="System.IO" %><%@ Import Namespace="System.Drawing" %><%@ Import Namespace="System.Drawing.Imaging" %><html><script runat =server> void UploadBtn_Click(Object sender, EventArgs e) { String filename; String filename1; String[] filename2; int q; filename=UploadFile.PostedFile.FileName ; filename2=filename.Split(new Char[] {'\\'}); q=filename2.GetUpperBound(0); filename1=filename2[q]; dis.Text="上传文件名:"+filename1+"<br/>"; UploadFile.PostedFile.SaveAs(Server.MapPath(filename1)); ImageEditor.Visible = true; dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数"; Image1.Src=filename1; } void UpdateBtn_Click(Object sender, EventArgs e) { String filename1; filename1=Image1.Src; System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1)); System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRgb); Graphics g = Graphics.FromImage(newimage); g.DrawImage(image,0,0,image.Width,image.Height); Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text)); Brush b = new SolidBrush(Color.Red); g.DrawString(Caption.Text, f, b, 10, 140); g.Dispose(); //System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Convert.ToInt32(Width.Text),Convert.ToInt32(Height.Text),null,0); image.Dispose(); // thumbImage.Save(Server.MapPath(filename1), ImageFormat.Jpeg); Image1.Src=filename1; Caption.Text=""; } </script> <body> <asp:label id="dis" runat=server/> <form enctype="multipart/form-data" runat=server> <h3> Select File To Upload: <input id="UploadFile" type=file runat=server> <asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat=server/> <hr> <asp:panel id="ImageEditor" Visible=false runat=server> <img ID="Image1" src="" runat="server"/> <h3> Image Width: <asp:textbox id="Width" runat=server/> Image Height: <asp:textbox id="Height" runat=server/> <br/> Text Caption: <asp:textbox id="Caption" runat=server/> Caption Size: <asp:dropdownlist id="FontSize" runat=server> <asp:listitem>14</asp:listitem> <asp:listitem>18</asp:listitem> <asp:listitem>26</asp:listitem> <asp:listitem>36</asp:listitem> <asp:listitem>48</asp:listitem> <asp:listitem>62</asp:listitem> </asp:dropdownlist> Caption Font: <asp:dropdownlist id="FontType" runat=server> <asp:listitem>黑体</asp:listitem> <asp:listitem>仿宋</asp:listitem> <asp:listitem>隶书</asp:listitem> <asp:listitem>楷书</asp:listitem> <asp:listitem>方正姚体</asp:listitem> <asp:listitem>华文彩云</asp:listitem> </asp:dropdownlist> <asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/> </h3> </asp:panel> </form> </body></html> 可不可以不要UploadFile.PostedFile.FileName 这样的语句,因为我的地址是从数据库里取出的,不能够点浏览的。 上海华贸国际货运公司ASP.NET面试题! GridView 显示未读消息怎么弄? C#TreeView控件的问题 sqlserver安装日志在哪差看?? 水晶报表页脚如何加入标签,如何以编程的方式访问?【在线等】【加分】 对URL加密的问题? 关于div的一个问题 如何实现每天的一时间点执行一任务? 问个入门问题,怎么在asp.net里面生成javasript客户端脚本? javascript和ActiveX的交互问题 数据绑定后控制字符的问题,在线急等!!!!!!!!!! 在form中使用web服务器控件,如何提交到另一个aspx页面处理
----------------------------------------------------------------------
欢迎试用ASP.NET大文件上传组件(AspnetUpload 1.0 Release & 无刷新进度条)
http://bestcomy.europe.webmatrixhosting.net
----------------------------------------------------------------------
{
imagePath= UpFileControl.PostedFile.FileName;
imageType= imagePath.Substring(imagePath.LastIndexOf(".")+1);
imageName = imagePath.Substring(imagePath.LastIndexOf("\\")+1); if("jpg" != imageType && "gif" != imageType)
{
Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
HttpPostedFile SendImage=UpFileControl.PostedFile;
imageSize=SendImage.ContentLength;////取得图片
imageBody=new Byte[imageSize];
Stream StreamObject=SendImage.InputStream;//建立数据流对象
StreamObject.Read(imageBody,0,imageSize);///把图像数据放到mMarkBody中,其中0代表数据指针位置,intFileLength代表要读取的流的长度 imagePath=UpFileControl.PostedFile.FileName;//取得图象路径 SqlCom="insert into Image(ImageName,Image,ImageSize) values('"+imageName+"','"+imageBody+"','"+imageSize.ToString()+"')";
con.Open();
cmd = new SqlCommand(SqlCom,con);
try
{
cmd.ExecuteNonQuery();
Response.Write("成功!");
}
catch
{
Response.Write("失败!");
}
con.Close();
}
}
try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch(System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
void UploadBtn_Click(Object sender, EventArgs e) {
String filename;
String filename1;
String[] filename2;
int q;
filename=UploadFile.PostedFile.FileName ;
filename2=filename.Split(new Char[] {'\\'});
q=filename2.GetUpperBound(0);
filename1=filename2[q];
dis.Text="上传文件名:"+filename1+"<br/>";
UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
ImageEditor.Visible = true;
dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
Image1.Src=filename1;
}
void UpdateBtn_Click(Object sender, EventArgs e) {
String filename1;
filename1=Image1.Src;
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRgb);
Graphics g = Graphics.FromImage(newimage);
g.DrawImage(image,0,0,image.Width,image.Height);
Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
Brush b = new SolidBrush(Color.Red);
g.DrawString(Caption.Text, f, b, 10, 140);
g.Dispose();
//System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Convert.ToInt32(Width.Text),Convert.ToInt32(Height.Text),null,0);
image.Dispose();
// thumbImage.Save(Server.MapPath(filename1), ImageFormat.Jpeg);
Image1.Src=filename1;
Caption.Text="";
} </script>
<asp:label id="dis" runat=server/>
<form enctype="multipart/form-data" runat=server> <h3> Select File To Upload: <input id="UploadFile" type=file runat=server> <asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat=server/> <hr>
<asp:panel id="ImageEditor" Visible=false runat=server> <img ID="Image1" src="" runat="server"/> <h3>
Image Width: <asp:textbox id="Width" runat=server/> Image Height: <asp:textbox id="Height" runat=server/> <br/> Text Caption: <asp:textbox id="Caption" runat=server/> Caption Size: <asp:dropdownlist id="FontSize" runat=server>
<asp:listitem>14</asp:listitem>
<asp:listitem>18</asp:listitem>
<asp:listitem>26</asp:listitem>
<asp:listitem>36</asp:listitem>
<asp:listitem>48</asp:listitem>
<asp:listitem>62</asp:listitem>
</asp:dropdownlist>
Caption Font: <asp:dropdownlist id="FontType" runat=server>
<asp:listitem>黑体</asp:listitem>
<asp:listitem>仿宋</asp:listitem>
<asp:listitem>隶书</asp:listitem>
<asp:listitem>楷书</asp:listitem>
<asp:listitem>方正姚体</asp:listitem>
<asp:listitem>华文彩云</asp:listitem>
</asp:dropdownlist>
<asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/> </h3>
</asp:panel> </form> </body>
</html>