.net常用的方法

來源:互聯網
上載者:User
       //用javascript判斷是否去那個頁面
      Response.Write("<script language=\"javascript\" type=\"text/javascript\">");
      Response.Write("if(confirm('是否去那個頁面。')){ document.URL='LookContent.aspx'}");
      Response.Write("</script>");

      //傳遞資訊時如果有中文最好用以下函數轉換一下HttpUtility.UrlEncode()
      http://www.abc.com/SameArticle.aspx?type=classify&title=" + HttpUtility.UrlEncode("標題")

      //擷取某頁面傳遞過來的問號資訊
      Request.QueryString["title"]

      //擷取伺服器路徑
      System.Web.HttpRuntime.AppDomainAppPath 

      //日期胡亂轉換
      string dtString = "19831015121015";
      IFormatProvider culture = new System.Globalization.CultureInfo("zh-CN", true);
      DateTime dt = DateTime.ParseExact(dtString, "yyyyMMddHHmmss", culture, DateTimeStyles.NoCurrentDateDefault); //大寫HH是24小時制,小寫hh是12小時制
      Console.WriteLine(dt.ToString());

      //DataTable 排序方法
        DataView dvBriefing = dtBriefing.DefaultView;
        dvBriefing.Sort = "CommentCount DESC";
        dtBriefing = dvBriefing.ToTable();

      //Asp.net 快速寫txt檔案
      StreamWriter swOutTime = new StreamWriter("c:\\TempOutTime.txt", true, System.Text.Encoding.GetEncoding("GB2312"));
      swOutTime.Write("寫入txt檔案");
      swOutTime.Flush();
      swOutTime.Close();

      //Asp.net DataTable寫XML
      1、寫用dtBriefing.WriteXml("C:\\temp.xml", XmlWriteMode.WriteSchema);
      2、讀用DataSet dllxml = new DataSet();
                    dllxml.ReadXml("C:\\temp.xml");
                    dtBriefing = dllxml.Tables[0]; 
          
        // 判斷是否合法的IP地址
        static private bool isIpAdd(string url)
        {
            url = CleanURL(url);
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"(\d{1,3}\.){3}\d{1,3}");
            if (url == reg.Match(url).ToString())
            {
                if (reg.Match(url).Success)
                {
                    string[] ips = url.Split('.');
                    if (ips.Length == 4 || ips.Length == 6)
                    {
                        if (System.Int32.Parse(ips[0]) < 256 && System.Int32.Parse(ips[1]) < 256 & System.Int32.Parse(ips[2]) < 256 & System.Int32.Parse(ips[3]) < 256)
                            return true;
                        else
                            return false;
                    }
                }
            }
            return false;
        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.