PasteCode.aspx
上传用户:lanchensha
上传日期:2022-02-27
资源大小:7530k
文件大小:8k
源码类别:

编辑器/阅读器

开发平台:

C#

  1. <%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" %>
  2. <%@ Register TagPrefix="CH" Namespace="ActiproSoftware.CodeHighlighter" Assembly="ActiproSoftware.CodeHighlighter.Net20" %>
  3. <%@ Import Namespace="DotNetTextBox" %>
  4. <%@ Import Namespace="ActiproSoftware.CodeHighlighter" %>
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html;charset=gb2312">
  8. <title><%=ResourceManager.GetString("codehighlighter")%></title>
  9. <base target="_self" />
  10. <link href="stylesheet.css" rel="stylesheet" type="text/css" />
  11.  <script runat=server language="C#">
  12.      protected void Page_Load(object sender, EventArgs e)
  13.      {
  14.          Response.Expires = -1;
  15.          
  16.          if (!IsPostBack)
  17.          {
  18.              CodeHighlighterConfiguration codeConfig = (CodeHighlighterConfiguration)System.Configuration.ConfigurationManager.GetSection("codeHighlighter");
  19.              string[] keys = new string[codeConfig.LanguageConfigs.Keys.Count];
  20.              codeConfig.LanguageConfigs.Keys.CopyTo(keys, 0);
  21.              Array.Sort(keys);
  22.              foreach (string key in keys)
  23.              {
  24.                  LanguageDropDownList.Items.Add(key);
  25.                  if (key == "C#")
  26.                  {
  27.                      LanguageDropDownList.SelectedIndex = LanguageDropDownList.Items.Count - 1;
  28.                  }
  29.              }
  30.              uploadCodebutton.Text = ResourceManager.GetString("uploadcodefile");
  31.              LineNumberMarginVisibleCheckBox.Text = ResourceManager.GetString("LineNumberMarginVisibleCheckBox");
  32.              OutliningEnabledCheckBox.Text = ResourceManager.GetString("OutliningEnabledCheckBox");
  33.              HighlightButton.Text = ResourceManager.GetString("HighlightButton");
  34.          }
  35.      }
  36.      private void HighlightButton_Click(object sender, System.EventArgs e)
  37.      {
  38.          Codehighlighter1.LanguageKey = LanguageDropDownList.SelectedItem.Text;
  39.          Codehighlighter1.OutliningEnabled = OutliningEnabledCheckBox.Checked;
  40.          Codehighlighter1.LineNumberMarginVisible = LineNumberMarginVisibleCheckBox.Checked;
  41.          Codehighlighter1.Text = CodeTextBox.Text.Replace("\", "\\");
  42.      }
  43.      private void uploadCode_Click(object sender, EventArgs e)
  44.      {
  45.          //Disable the button 
  46.          uploadCodebutton.Enabled = false;
  47.          //Update labels 
  48.          //FileNameLabel.Text = UploadFile.PostedFile.FileName;
  49.          //MimeTypeLabel.Text = UploadFile.PostedFile.ContentType;
  50.          //FileSizeLabel.Text = UploadFile.PostedFile.ContentLength.ToString();
  51.          CodeTextBox.Text = null;
  52.          if ((UploadFile.PostedFile.ContentLength > 30000))
  53.          {
  54.              Codehighlighter1.LanguageKey = null;
  55.              Codehighlighter1.Text = ResourceManager.GetString("uploadcodefileerror");
  56.          }
  57.          else
  58.          {
  59.              //Set the language key 
  60.              Codehighlighter1.LanguageKey = LanguageDropDownList.SelectedItem.Text;
  61.              //Set whether to allow outlining and line numbering 
  62.              Codehighlighter1.OutliningEnabled = OutliningEnabledCheckBox.Checked;
  63.              Codehighlighter1.LineNumberMarginVisible = LineNumberMarginVisibleCheckBox.Checked;
  64.              //Set the code to the highlighter 
  65.              System.IO.StreamReader reader = new System.IO.StreamReader(UploadFile.PostedFile.InputStream);
  66.              Codehighlighter1.Text = reader.ReadToEnd().Replace("\", "\\");
  67.          }
  68.      }
  69.      #region Web 窗体设计器生成的代码
  70.      override protected void OnInit(EventArgs e)
  71.      {
  72.          //
  73.          // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  74.          //
  75.          InitializeComponent();
  76.          base.OnInit(e);
  77.      }
  78.      /// <summary>
  79.      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  80.      /// 此方法的内容。
  81.      /// </summary>
  82.      private void InitializeComponent()
  83.      {
  84.          this.HighlightButton.Click += new System.EventHandler(this.HighlightButton_Click);
  85.      }
  86.      #endregion
  87.      public void CodeHighlighter_PostRender(object sender, System.EventArgs e)
  88.      {
  89.          if (IsPostBack)
  90.          {
  91.              string code = Codehighlighter1.Output.Replace(""", "\"");
  92.              code = code.Replace("rn", "<br>"+rn"");
  93.              string codstyle = @"<div style='BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee'>";
  94.              if (HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"].ToLower().IndexOf("msie") == -1)
  95.              {
  96.                  ClientScript.RegisterStartupScript(typeof(Page), "Key", @"window.opener.plugin_execommand(""" + codstyle + code + @"</div>"");window.parent.close();", true);
  97.              }
  98.              else
  99.              {
  100.                  ClientScript.RegisterStartupScript(typeof(Page), "Key", @"window.parent.returnValue =""" + codstyle + code + @"</div>"";window.parent.close();", true);
  101.              }
  102.          }
  103.      }
  104.  </script>
  105. </head>
  106. <body topmargin="10">
  107. <form id="code" runat="server">
  108. <table border="0" cellpadding="0"cellspacing="0" width="100%">
  109. <tr>
  110. <td align="center">
  111. <div align="center">
  112. <table border=1 style="border-style:dashed ;"  bordercolor="#cccccc" >
  113. <tr>
  114. <td style="width: 86px; height: 32px" align="right">
  115.                             <%=ResourceManager.GetString("codetype")%>:</td>
  116. <td style="width: 483px; height: 32px">
  117.                             &nbsp;<asp:DropDownList Runat="server" ID="LanguageDropDownList" Width="69px" />&nbsp;
  118.                             &nbsp;<asp:CheckBox Runat="server" ID="LineNumberMarginVisibleCheckBox" />&nbsp;<asp:CheckBox
  119.                                 ID="OutliningEnabledCheckBox" runat="server" />
  120.                             <br />
  121.                         </td>
  122. </tr>
  123.                     <tr>
  124.                         <td align="right" style="width: 86px; height: 32px">
  125.                             <%=ResourceManager.GetString("codefile")%>:</td>
  126.                         <td>
  127.                             &nbsp;<input id="UploadFile" runat="server" name="UploadFile" type="file" />
  128.                             <asp:Button ID="uploadCodebutton" runat="server" OnClick="uploadCode_Click" />
  129.                         </td>
  130.                     </tr>
  131. <tr>
  132. <td style="width: 86px; height: 320px;" align="right">
  133.                             <%=ResourceManager.GetString("codecontent")%>:<br />
  134.                             [<%=ResourceManager.GetString("pastecode")%>]</td>
  135. <td style="width: 483px;" align="center"><asp:TextBox Runat="server" ID="CodeTextBox" TextMode="MultiLine" Rows="10" Columns="80" Height="320px" Width="475px" BorderColor="Gray" BorderStyle="Dashed" BorderWidth="1px"/></td>
  136. </tr>
  137. <tr>
  138. <td style="height: 30px;" align="center" colspan="2"><asp:button id="HighlightButton" Runat="server"></asp:button>
  139.                             <input type=Button ID="close" value="<%=ResourceManager.GetString("close2")%>"  OnClick="window.close()"/></td>
  140. </tr>
  141. </table>
  142. </div>
  143. </td>
  144. <td></td>
  145. </tr>
  146. <tr>
  147. <td class="FooterBar" colspan="2" align="center"></TD>
  148. </tr>
  149. </table>
  150. <pre><ch:codehighlighter id="Codehighlighter1" runat="server" onpostrender="CodeHighlighter_PostRender"></ch:codehighlighter></pre>
  151. </form>
  152. </body>
  153. <script language=javascript>
  154. var userAgent = navigator.userAgent.toLowerCase();
  155. var is_ie = (userAgent.indexOf('msie') != -1);
  156. if(is_ie)
  157. {
  158. document.body.bgColor="ButtonFace";
  159. }
  160. else
  161. {
  162. document.body.bgColor="#E0E0E0";
  163. }
  164. </script>
  165. </html>