自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

介紹ASP.NET上傳

開發(fā) 后端
本文介紹ASP.NET上傳,KindEditor是一個不錯的網(wǎng)頁在線編輯器,可是它只提供了asp,php,jsp上傳的類,沒有提供ASP.NET上傳的類。

KindEditor是一個不錯的網(wǎng)頁在線編輯器,可是它只提供了asp,php,jsp上傳的類,沒有提供ASP.NET上傳的類。

ASP.NET上傳代碼:

  1. using System;  
  2. using System.Globalization;  
  3. using System.Collections;  
  4. using System.Configuration;  
  5. using System.Data;  
  6. using System.Web;  
  7. using System.Web.Security;  
  8. using System.Web.UI;  
  9. using System.Web.UI.HtmlControls;  
  10. using System.Web.UI.WebControls;  
  11. using System.Web.UI.WebControls.WebParts;  
  12.  
  13. public partial class Jscript_KindEditor_upload_cgi_upload : System.Web.UI.Page  
  14. {  
  15. protected void Page_Load(object sender, EventArgs e)  
  16. {  
  17. //文件保存目錄路徑  
  18. string SavePath = "/Upload_Images/";  
  19. //文件保存目錄URL  
  20. string SaveUrl = "/Upload_Images/";  
  21. //上傳圖片類型  
  22. string[] ExtStr=new string[4];  
  23. ExtStr[0] = ".gif";  
  24. ExtStr[1] = ".jpg";  
  25. ExtStr[2] = ".png";  
  26. ExtStr[3] = ".bmp";  
  27. //圖片的***大小  
  28. int MaxSize = 100000;  
  29. //錯誤提示  
  30. string[] MsgStr = new string[3];  
  31. MsgStr[0] = "上傳文件大小超過限制.";  
  32. MsgStr[1] = "上傳文件擴(kuò)展名是不允許的擴(kuò)展名.";  
  33. MsgStr[2] = "上傳文件失敗\\n請重試.";  
  34.  
  35. string imgWidth = Request.Form["imgWidth"];  
  36. string imgHeight = Request.Form["imgHeight"];  
  37. string imgBorder = Request.Form["imgBorder"];  
  38. string imgTitle = Request.Form["imgTitle"];  
  39. string imgAlign = Request.Form["imgAlign"];  
  40. string imgHspace = Request.Form["imgHspace"];  
  41. string imgVspace = Request.Form["imgVspace"];  
  42.  
  43. HttpPostedFile imgFile = HttpContext.Current.Request.Files["imgFile"];  
  44. //獲得文件名  
  45. string FileName = System.IO.Path.GetFileName(imgFile.FileName);  
  46.  
  47. if (FileName != "")  
  48. {  
  49. if (imgFile.ContentLength > MaxSize)  
  50. {  
  51. Alert(MsgStr[0]);  
  52. }  
  53. else  
  54. {  
  55. string fileExtension = System.IO.Path.GetExtension(FileName).ToLower();  
  56. if (CheckExt(ExtStr, fileExtension))  
  57. {  
  58. //重新為文件命名,時間毫秒部分+擴(kuò)展名  
  59. string imgReName = "" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ffff", 
    DateTimeFormatInfo.InvariantInfo) + "" + fileExtension;  
  60. //文件夾名  
  61. string imgFolderName=DateTime.Now.ToString
    ("yyyyMMdd",DateTimeFormatInfo.InvariantInfo);  
  62.  
  63. try  
  64. {  
  65.  
  66. if (!System.IO.Directory.Exists(@Server.MapPath
    ("" + SavePath + "" +imgFolderName + "")))  
  67. {  
  68. //生成文件完整目錄  
  69. System.IO.Directory.CreateDirectory(@Server.MapPath
    ("" + SavePath + "" +imgFolderName + ""));  
  70. }  
  71.  
  72. imgFile.SaveAs(@Server.MapPath
    ("" + SavePath + "" + imgFolderName + "/")+imgReName);  
  73.  
  74.  
  75. }  
  76. catch  
  77. {  
  78. Alert(MsgStr[2]);  
  79. }  
  80. string imgUrl = SaveUrl + imgFolderName + "/" + imgReName;  
  81. ReturnImg(imgUrl, imgWidth, imgHeight, imgBorder, 
    imgTitle, imgAlign, imgHspace, imgVspace);  
  82.  
  83. }  
  84. else  
  85. {  
  86. Alert(MsgStr[1]);  
  87. }  
  88. }  
  89. }  
  90.  
  91.  
  92. }  
  93. /// <summary> 
  94. /// 提示關(guān)閉層  
  95. /// </summary> 
  96. /// <param name="MsgStr"></param> 
  97. private void Alert(string MsgStr)  
  98. {  
  99.  
  100. Response.Write("<html>");  
  101. Response.Write("<head>");  
  102. Response.Write("<title>error</title>");  
  103. Response.Write("<meta http-equiv=\"content-type\" content=\"text/html;
     
    charset=utf-8\">");  
  104. Response.Write("</head>");  
  105. Response.Write("<body>");  
  106. Response.Write("<script type=\"text/javascript\">alert(\"" + MsgStr + "\");
    parent.KindDisableMenu();parent.KindReloadIframe();
    </script>");  
  107. Response.Write("</body>");  
  108. Response.Write("</html>");  
  109. }  
  110. /// <summary> 
  111. /// 檢測文件類型  
  112. /// </summary> 
  113. /// <param name="ExtStr"></param> 
  114. /// <param name="fileExt"></param> 
  115. /// <returns></returns> 
  116. private bool CheckExt(string[] ExtStr,string fileExt)  
  117. {  
  118. for (int i = 0; i < ExtStr.Length; i++)  
  119. {  
  120. if (ExtStr[i] != fileExt)  
  121. {  
  122. return true;  
  123. }  
  124. }  
  125. return false;  
  126. }  
  127. /// <summary> 
  128. /// 返回圖片  
  129. /// </summary> 
  130. /// <param name="FileUrl"></param> 
  131. /// <param name="FileWidth"></param> 
  132. /// <param name="FileHeight"></param> 
  133. /// <param name="FileBorder"></param> 
  134. /// <param name="FileTitle"></param> 
  135. /// <param name="FileAlign"></param> 
  136. /// <param name="FileHspace"></param> 
  137. /// <param name="FileVspace"></param> 
  138. private void ReturnImg( string FileUrl,string FileWidth,string FileHeight,
    string FileBorder,string FileTitle,string FileAlign,string FileHspace,string FileVspace)  
  139. {  
  140. Response.Write("<html>");  
  141. Response.Write("<head>");  
  142. Response.Write("<title>上傳成功</title>");  
  143. Response.Write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");  
  144. Response.Write("</head>");  
  145. Response.Write("<body>");  
  146. Response.Write("<script type=\"text/javascript\">parent.KindInsertImage
    (\"" + FileUrl +"\",\"" + FileWidth + "\",\"" + FileHeight + "\",\"" + 
    FileBorder + "\",\"" + FileTitle + "\",\"" + FileAlign + "\",\"" + 
    FileHspace + "\",\"" + FileVspace + "\");
    </script>");  
  147. Response.Write("</body>");  
  148. Response.Write("</html>");  
  149. }  

ASP.NET上傳代碼,希望對大家有用。

【編輯推薦】

  1. ASP.NET中的數(shù)據(jù)源控件
  2. 介紹ASP.NET的XML Web服務(wù)使用
  3. ASP.NET應(yīng)用程序的web.config文件
  4. 概述ASP.NET XML Web服務(wù)
  5. ASP.NET中實(shí)現(xiàn)HTTP請求
責(zé)任編輯:佚名 來源: IT168
相關(guān)推薦

2009-07-29 09:14:36

ASP.NET網(wǎng)站

2009-07-21 10:40:36

ASP.NET Pro

2009-07-29 17:26:39

ASP.NET頁面

2009-07-23 14:17:41

2009-09-10 14:02:08

LINQ ASP.NE

2009-07-20 16:12:21

ASP.NET Fra

2009-07-27 17:00:29

ASP.NET主機(jī)

2009-08-19 09:23:40

ASP.NET Rou

2009-07-29 17:23:17

ASP.NET表單

2009-07-22 16:05:34

ASP.NET AJA

2009-08-03 17:35:07

ASP.NET WebASP.NET編程工具

2009-07-29 09:53:24

ASP.NET異常管理

2009-07-24 13:39:03

ASP.NET彈出窗口

2009-07-21 15:11:14

ASP.NET Rou

2009-07-29 10:35:51

ASP.NET緩存

2009-08-05 15:57:03

ASP.NET控件ID

2009-07-20 10:53:59

ASP.NET MVC

2009-08-05 10:36:08

開發(fā)ASP.NET

2009-07-21 15:38:31

2009-07-20 16:56:16

SQL語句ASP.NET
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號