Asp.net源码专业站
首页->博客空间->WO@BIZ第一季1.2版源码>>controls/UpMultiFileControl.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:WO@BIZ第一季1.2版源码
当前文件:文件类型 WOBIZ/controls/UpMultiFileControl.aspx.cs[8K,2009-6-12 11:58:35]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Text.RegularExpressions; 12using System.Drawing; 13using WoNextDll.commen; 14 15public partial class Controls_UpMultiFileControl : System.Web.UI.Page 16{ 17 protected SymmetricMethod sm = new SymmetricMethod(); 18 19 protected void Page_Load(object sender, EventArgs e) 20 { 21 if (Request.Cookies["WONEXT_COOKIE"] == null || Session["WONEXT_NOLOING"] != null) 22 { 23 Response.Write("请登陆后再上传图片,谢谢"); 24 Response.End(); 25 } 26 } 27 28 protected string UserFilesDirectory(string imageuploadpath) 29 { 30 string UserPath = Server.MapPath(imageuploadpath + sm.Decrypto(Request.Cookies["WONEXT_COOKIE"]["_UserID"].ToString())); 31 string UserPath2 = imageuploadpath + sm.Decrypto(Request.Cookies["WONEXT_COOKIE"]["_UserID"].ToString()); 32 33 if (!System.IO.Directory.Exists(UserPath)) //创建相应的文件夹 34 { 35 System.IO.Directory.CreateDirectory(UserPath); 36 } 37 return UserPath2 + "/"; 38 } 39 40 protected void AddLogo(System.Drawing.Size size, string strFile, System.Drawing.Image image) 41 { 42 System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height); //新建bmp图片 43 44 System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap); //新建画板 45 46 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量插值法 47 48 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //设置高质量,低速度呈现平滑程度 49 50 graphics.Clear(Color.White); //清空画布 51 //在指定位置画图 52 graphics.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), 53 54 new System.Drawing.Rectangle(0, 0, image.Width, image.Height), 55 56 System.Drawing.GraphicsUnit.Pixel); 57 58 //文字水印 59 //System.Drawing.Graphics textGraphics = System.Drawing.Graphics.FromImage(bitmap); 60 //System.Drawing.Font font = new Font("宋体", 10, FontStyle.Bold); 61 //System.Drawing.Brush brush = new SolidBrush(Color.Red); 62 //textGraphics.DrawString("我靠,测试下", font, brush, 10, 10); 63 //textGraphics.Dispose(); 64 65 ///图片水印 66 67 //System.Drawing.Image copyImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath("pic/1.gif")); 68 69 //Graphics a = Graphics.FromImage(bitmap); 70 71 //a.DrawImage(copyImage, new Rectangle(bitmap.Width-copyImage.Width,bitmap.Height-copyImage.Height,copyImage.Width, copyImage.Height),0,0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel); 72 73 //copyImage.Dispose(); 74 75 //a.Dispose(); 76 77 //copyImage.Dispose(); 78 79 //保存图 80 81 try 82 { 83 bitmap.Save(Server.MapPath(strFile), System.Drawing.Imaging.ImageFormat.Jpeg); 84 } 85 86 catch (Exception ex) 87 { 88 Response.Write("保存缩略图失败:" + ex.Message); 89 } 90 graphics.Dispose(); 91 image.Dispose(); 92 bitmap.Dispose(); 93 } 94 95 protected void UploadButton_Click(object sender, EventArgs e) 96 { 97 string txtname = Request.QueryString["t"].ToString(); 98 99 ///'遍历File表单元素 100 HttpFileCollection files = HttpContext.Current.Request.Files; 101 102 /// '状态信息 103 //System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); 104 //strMsg.Append("上传的文件分别是:<hr color=red>"); 105 string imgvalue = ""; 106 int upfilecount = 0; 107 try 108 { 109 for (int iFile = 0; iFile < files.Count; iFile++) 110 { 111 ///'检查文件扩展名字 112 HttpPostedFile postedFile = files[iFile]; 113 string fileName, fileExtension; 114 fileName = System.IO.Path.GetFileName(postedFile.FileName); 115 if (fileName != "") 116 { 117 fileExtension = System.IO.Path.GetExtension(fileName).Substring(1).ToLower(); 118 //Regex r3 = new Regex(@"(jpg)|(bmp)|(gif)|(png)|()", RegexOptions.IgnoreCase); 119 string aa="jpg,gif,bmp,png,"; 120 int aaaa = aa.IndexOf(fileExtension); 121 if (aa.IndexOf(fileExtension) >= 0) 122 { 123 if (postedFile.ContentLength > 1024 * 1024 * 10) 124 { 125 JScriptAlert("你要上传的这张" + fileName + "太大了,没上传成功!"); 126 } 127 else 128 { 129 string newfileName = DateTime.Now.ToString("yyyyMMddhhmmssfff").ToString() + iFile + "." + fileExtension; 130 string p = UserFilesDirectory("../upimages/"); 131 132 //postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(p) + newfileName); 133 System.Drawing.Image image = System.Drawing.Image.FromStream(postedFile.InputStream, true); 134 System.Drawing.Size size = new Size(image.Width,image.Height); // 图片大小 135 this.AddLogo(size, p + newfileName, image); 136 137 // 生成缩略图 138 //原始图片名称 139 string originalFilename = postedFile.FileName; 140 //生成的高质量图片名称 141 string strFile = p + newfileName.Substring(0, newfileName.IndexOf('.')) + "_s" + newfileName.Substring(newfileName.IndexOf('.')); 142 //从文件取得图片对象 143 image = System.Drawing.Image.FromStream(postedFile.InputStream, true); 144 Double Width = Double.Parse("120"); 145 Double Height = Double.Parse("90"); 146 System.Double NewWidth, NewHeight; 147 if (image.Width > image.Height) 148 { 149 NewWidth = Width; 150 NewHeight = image.Height * (NewWidth / image.Width); 151 } 152 else 153 { 154 NewHeight = Height; 155 NewWidth = (NewHeight / image.Height) * image.Width; 156 } 157 if (NewWidth > Width) 158 { 159 NewWidth = Width; 160 } 161 if (NewHeight > Height) 162 { 163 NewHeight = Height; 164 } 165 size = new Size((int)NewWidth, (int)NewHeight); // 图片大小 166 this.AddLogo(size, strFile, image); 167 168 169 imgvalue += p.Substring(3) + newfileName + ","; 170 upfilecount = upfilecount + 1; 171 } 172 } 173 else 174 { 175 JScriptAlert("你要上传的文件: " + fileName + " 不是图片类型的,请选择图片类型的图片上传,谢谢!"); 176 } 177 } 178 } 179 //strStatus.Text = strMsg.ToString(); 180 string txtid = "ctl00$ContentPlaceHolder1$" + txtname; 181 string a = "<script language=\"javascript\"> window.opener.document.getElementById('" + txtid + "').value+='" + imgvalue + "';</script>"; 182 Response.Write(a); 183 string a2 = "<script language=\"javascript\"> window.opener.document.getElementById('ctl00$ContentPlaceHolder1$TextBox1').value+='" + imgvalue + "';</script>"; 184 Response.Write(a2); 185 Response.Write("<script language=\"javascript\">window.opener.document.getElementById('ctl00$ContentPlaceHolder1$Label2').value='已经成功上传了" + upfilecount + "张图片,请不要修改文本框的内容!';</script>"); 186 Response.Write("<script language=\"javascript\">window.close();</script>"); 187 //return true; 188 } 189 catch (System.Exception Ex) 190 { 191 strStatus.Text = Ex.Message; 192 //return false; 193 } 194 195 } 196 protected void JScriptAlert(String Message) 197 { 198 Response.Write("<script language=\"javascript\">\n alert(\"" + Message + "\");\n</script>"); 199 //Response.End(); 200 } 201} 202
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:WO@BIZ第一季1.2版源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146