Asp.net源码专业站
首页->企业网站->EduMis信息发布系统源码>>App-Code/Common.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:EduMis信息发布系统源码
当前文件:文件类型 EduMis/App_Code/Common.cs[7K,2009-6-12 11:41:43]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Web; 5using System.Web.Security; 6using System.Web.UI; 7using System.Web.UI.WebControls; 8using System.Web.UI.WebControls.WebParts; 9using System.Web.UI.HtmlControls; 10using System.Text.RegularExpressions; 11using System.IO; 12using System.Net; 13/// Download from www.51aspx.com(51aspx.com) 14 15/// <summary> 16/// Common 的摘要说明 17/// </summary> 18 public class Common 19 { 20 public Common() 21 { 22 // 23 // TODO: 在此处添加构造函数逻辑 24 // 25 } 26 /// <summary> 27 /// 获取文本编辑器的数据,并自动上传远程图片 28 /// </summary> 29 /// <param name="uc">文本编辑器数据</param> 30 /// <returns></returns> 31 public string GetText(string str) 32 { 33 string mycontext = Regex.Replace(str, @"src[^>]*[^/].(?:jpg|bmp|gif|png|jpeg|JPG|BMP|GIF|JPEG)(?:\""|\')", new MatchEvaluator(SaveYuanFile)); 34 35 return mycontext; 36 } 37 38 39 40 private string SaveYuanFile(Match m) 41 { 42 string imgurl = ""; 43 string matchstr = m.Value;//str[i].ToString(); 44 string tempimgurl = ""; 45 tempimgurl = matchstr.Substring(5); 46 tempimgurl = tempimgurl.Substring(0, tempimgurl.IndexOf("\"")); 47 48 Regex re = new Regex(@"^http://*"); 49 if (re.Match(tempimgurl).Success) 50 { 51 matchstr = matchstr.Substring(5); 52 matchstr = matchstr.Substring(0, matchstr.IndexOf("\"")); 53 54 //Response.Write(matchstr + "<br>"); 55 56 //远程文件保存路径 57 string Folders = ConfigurationManager.AppSettings["yuanimg"].ToString(); 58 string fullname = matchstr; 59 60 string huozui = fullname.Substring(fullname.LastIndexOf(".")); 61 string filename = Common.GetFileName(); 62 string path = Folders + filename + huozui; 63 //Folders+fullname.Substring(fullname.LastIndexOf("\\") + 1); 64 65 if (System.IO.File.Exists(System.Web.HttpContext.Current.Request.MapPath(path))) 66 System.IO.File.Delete(System.Web.HttpContext.Current.Request.MapPath(path)); 67 GetHttpFile(matchstr, System.Web.HttpContext.Current.Request.MapPath(path)); 68 imgurl = "src=\"" + path.Replace("~/", "") + "\""; 69 } 70 else 71 { 72 imgurl = matchstr; 73 } 74 75 76 return imgurl; 77 } 78 79 80 string sException = null; 81 private bool GetHttpFile(string sUrl, string sSavePath) 82 { 83 bool bRslt = false; 84 WebResponse oWebRps = null; 85 WebRequest oWebRqst = WebRequest.Create(sUrl); 86 oWebRqst.Timeout = 100000; 87 try 88 { 89 oWebRps = oWebRqst.GetResponse(); 90 } 91 catch (WebException e) 92 { 93 sException = e.Message.ToString(); 94 } 95 catch (Exception e) 96 { 97 sException = e.ToString(); 98 } 99 finally 100 { 101 if (oWebRps != null) 102 { 103 BinaryReader oBnyRd = new BinaryReader(oWebRps.GetResponseStream(), System.Text.Encoding.GetEncoding("GB2312")); 104 int iLen = Convert.ToInt32(oWebRps.ContentLength); 105 FileStream oFileStream; 106 try 107 { 108 if (File.Exists(System.Web.HttpContext.Current.Request.MapPath("RecievedData.tmp"))) 109 { 110 oFileStream = File.OpenWrite(sSavePath); 111 } 112 else 113 { 114 oFileStream = File.Create(sSavePath); 115 } 116 oFileStream.SetLength((Int64)iLen); 117 oFileStream.Write(oBnyRd.ReadBytes(iLen), 0, iLen); 118 oFileStream.Close(); 119 } 120 catch (Exception ex) 121 { 122 //bRslt= false; 123 } 124 finally 125 { 126 oBnyRd.Close(); 127 oWebRps.Close(); 128 129 } 130 bRslt = true; 131 132 } 133 } 134 return bRslt; 135 136 } 137 138 /// <summary> 139 /// 文件上传 140 /// </summary> 141 /// <param name="fileupload">文件上传实例</param> 142 /// <returns>保存的文件名称</returns> 143 public static string UpLoadFile(FileUpload fileupload, string Folders) 144 { 145 //string Folders = "~/admin/eWebEditor/UpLoadFile/"; 146 string fullname = fileupload.PostedFile.FileName; 147 if ((fullname == null) || (fullname.Equals(""))) 148 return ""; 149 string huozui = fullname.Substring(fullname.LastIndexOf(".")); 150 string filename = GetFileName(); 151 string p1 = Folders + filename + huozui; 152 //Folders + fullname.Substring(fullname.LastIndexOf("\\") + 1); 153 string path = System.Web.HttpContext.Current.Server.MapPath(p1); 154 155 if (System.IO.File.Exists(path)) 156 System.IO.File.Delete(path); 157 fileupload.PostedFile.SaveAs(path); 158 return p1; 159 } 160 161 public static string GetFileName() 162 { 163 System.Threading.Thread.Sleep(1000); 164 string str1 = System.DateTime.Now.Year.ToString() + "-"; 165 166 if ((System.DateTime.Now.Month).ToString().Length < 2) 167 { 168 str1 += "0" + System.DateTime.Now.Month.ToString() + "-"; 169 } 170 else 171 { 172 str1 += System.DateTime.Now.Month.ToString() + "-"; 173 } 174 175 if ((System.DateTime.Now.Day).ToString().Length < 2) 176 { 177 str1 += "0" + System.DateTime.Now.Day.ToString() + "-"; 178 } 179 else 180 { 181 str1 += System.DateTime.Now.Day.ToString() + "-"; 182 } 183 184 if ((System.DateTime.Now.Hour).ToString().Length < 2) 185 { 186 str1 += "0" + System.DateTime.Now.Hour.ToString() + "-"; 187 } 188 else 189 { 190 str1 += System.DateTime.Now.Hour.ToString() + "-"; 191 } 192 193 if ((System.DateTime.Now.Minute).ToString().Length < 2) 194 { 195 str1 += "0" + System.DateTime.Now.Minute.ToString() + "-"; 196 } 197 else 198 { 199 str1 += System.DateTime.Now.Minute.ToString() + "-"; 200 } 201 202 if ((System.DateTime.Now.Second).ToString().Length < 2) 203 { 204 str1 += "0" + System.DateTime.Now.Second.ToString(); 205 } 206 else 207 { 208 str1 += System.DateTime.Now.Second.ToString(); 209 } 210 211 return str1; 212 } 213 214 }
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:EduMis信息发布系统源码
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146