目录文件创建
//设置文件路径 string filePath = @"D:file"; //判断路径目录是否存在 if (!Directory.Exists(filePath)) { //创建该路径目录 Directory.CreateDirectory(filePath); }
返回JSON数据
object obj = new object(); obj = new { errCode = 0, errMessage = "成功!" }; return JsonConvert.SerializeObject(obj);
NameValueCollection
//介绍: //NameValueCollection继承自NameObjectCollectionBase,并且和一般的键值对不同的是,它支持集合中出现相同的Key。 //在读取相同的key时,输出结果对Value进行了合并,这就是NameValueCollection与一般键值对的主要区别所在。 //代码示例: NameValueCollection data = new NameValueCollection(); data.Add("id","1"); data.Add("name","2"); data.Add("id","2"); context.Response.Write(data["id"]); //注: //引用:using System.Collections.Specialized; //举例:输出data["id"]的值为1,2
MD5加密
using System.Text; using System.Security.Cryptography; /// <summary> /// MD5加密 /// </summary> /// <param name="input"></param> /// <returns></returns> private static string GetMd5Hash(string input) { MD5 md5Hash = MD5.Create(); byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); string strResult = BitConverter.ToString(data); strResult = strResult.Replace("-", ""); return strResult; }
获取当前日期时间戳
/// <summary> /// 获取当前日期时间戳 /// </summary> /// <returns></returns> public static string GetTimeStamp() { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); return Convert.ToInt64(ts.TotalSeconds).ToString(); }
Base64加密
using System.Text; /// <summary> /// Base64加密 /// </summary> /// <param name="Message"></param> /// <returns></returns> public string Base64Code(string Message) { byte[] bytes = Encoding.Default.GetBytes(Message); return Convert.ToBase64String(bytes); }