zoukankan      html  css  js  c++  java
  • CommonHelper 公共类

      public static class CommonHelper 公共帮助类

    using System.Collections.Generic;
    using System.Linq;
    using System.Text.RegularExpressions;
    using System.Web;
    
    namespace AspNetAshx
    {
        public static class CommonHelper
        {
            #region 1.0 根据相对路径 读取 文件的内容字符串 +string GetFileContent(string filePath)
            /// <summary>
            /// 根据相对路径 读取 文件的内容字符串
            /// </summary>
            /// <param name="filePath">文件的相对路径</param>
            /// <returns></returns>
            public static string GetFileContent(string filePath)
            {
                //根据相对路径(虚拟路径) 获取 绝对路径(物理路径)
                string phyPath = HttpContext.Current.Server.MapPath(filePath);
                //读取文件内容
                string strContent = System.IO.File.ReadAllText(phyPath);
                //返回文件内容
                return strContent;
            } 
            #endregion
    
            #region 2.0 直接输出 js消息 并完成跳转 +WriteJs(string msg, string url)
            /// <summary>
            /// 直接输出 js 消息
            /// </summary>
            /// <param name="msg"></param>
            public static void WriteJs(string msg)
            {
                HttpContext.Current.Response.Write("<script>alert('" + msg + "');</script>");
            }
            /// <summary>
            /// 直接输出 js消息 并完成跳转
            /// </summary>
            /// <param name="msg"></param>
            /// <param name="url"></param>
            public static void WriteJs(string msg, string url)
            {
                HttpContext.Current.Response.Write("<script>alert('" + msg + "');window.location='" + url + "';</script>");
            } 
            #endregion
    
            #region 3.0 使用正则表达式验证 参数 是否为数值 +bool IsNum(string strNumber)
            /// <summary>
            /// 使用正则表达式验证 参数 是否为数值
            /// </summary>
            /// <param name="strNumber"></param>
            /// <returns></returns>
            public static bool IsNum(string strNumber)
            {
                Regex reg = new Regex(@"^d+$");//数值正则表达式(一个或多个数字)
                return reg.IsMatch(strNumber);
            } 
            #endregion
        }
    }
  • 相关阅读:
    ADO.NET 之 二 yz
    ADO.NET 之 三 yz
    telerik的RadAutoCompleteBox控件学习完结 yz
    ADO.NET 之 三 2 yz
    ASP.NET 底层技术 一 yz
    telerik的RadAutoCompleteBox控件学习三 yz
    ASP.NET 之 自定义 异步HTTP处理程序 yz
    javascriptArray类型 二 yz
    telerik的RadAutoCompleteBox控件学习一 yz
    javascript——Array类型 yz
  • 原文地址:https://www.cnblogs.com/hehehehehe/p/5106504.html
Copyright © 2011-2022 走看看