随笔分类 -  C#

打印html页面部分内容
摘要:function PrintPage(){var newstr = document.getElementById("printContent").innerHTML;var oldstr = document.body.innerHTML;document.body.innerHTML = newstr;window.print();document.body.innerHTML = oldstr;return false; } 阅读全文
posted @ 2011-10-12 14:44 一直在前进 阅读(570) 评论(0) 推荐(0)
DAL层利用反射获取数据列表,增加和修改数据
摘要:一般DAL层都会涉及到往表里添加和修改数据,根据Model设置SqlParameter[],以及将datarow数据转化为Model,利用泛型和反射,可以大大简化代码。首先是DalHelper类public static class DalHelper<T> where T : new() { #region SqlParameter /// <summary> /// 通过Model类获取属性的SqlParameter数组 /// </summary> /// <param name="classObject">Model类 阅读全文
posted @ 2011-09-21 17:05 一直在前进 阅读(885) 评论(4) 推荐(1)
asp.net 替换字符串,正则替换字符串,不区分大小写替换字符串,替换html标签
摘要:using System;using System.Text;using System.Text.RegularExpressions;//这个一定要加 namespace EC {/// <summary>/// 替换字符串/// </summary>public class StringRepStrs { public StringRepStrs () {} #region 普通替换字符串 /// <summary>/// 普通替换字符串 /// </summary>/// <param name="src"> 阅读全文
posted @ 2011-08-02 14:34 一直在前进 阅读(698) 评论(0) 推荐(0)
cookie读、写、删除
摘要:创建cookievar cookie = new HttpCookie("member");cookie.Values.Add("memberName", name);cookie.Values.Add("memberType", type.ToString());cookie.Expires = DateTime.Now.AddDays(30);Response.Cookies.Add(cookie);读Cookievar cookie = Request.Cookies["member"];if (cookie 阅读全文
posted @ 2011-07-18 11:29 一直在前进 阅读(249) 评论(0) 推荐(0)
.net发送邮件
摘要:需引用 System.Net.Mail;public void SendEmail(string from,string to,string subject, string body) { MailMessage message = new MailMessage(from,to); message.Subject = subject; message.IsBodyHtml = true; message.Body = body; SmtpClient client = new SmtpClient("smtp.163.com"); client.Credentials = 阅读全文
posted @ 2011-06-29 11:45 一直在前进 阅读(155) 评论(0) 推荐(0)
使用反射访问属性
摘要:[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple = true) // multiuse attribute]public class Author : System.Attribute{ string name; public double version; public Author(string name) { this.name = name; version = 1.0; // Default value } public strin 阅读全文
posted @ 2011-06-21 12:33 一直在前进 阅读(241) 评论(0) 推荐(0)
利用.Net自带的Compression压缩和解压缩文件
摘要:using System;using System.IO;using System.Text;using System.Windows.Forms;using System.IO.Compression;using System.Collections.Generic; namespace CompressionSample{ class ZipUtil { public void CompressFile(string iFile, string oFile) { //判断文件是否存在 if (File.Exists(iFile) == false) { throw new FileNotF 阅读全文
posted @ 2011-06-20 12:00 一直在前进 阅读(816) 评论(0) 推荐(0)
解析URL(可以正确识别UTF-8和GB2312编码)
摘要:/// <summary> /// 解析URL(可以正确识别UTF-8和GB2312编码) /// </summary> /// <param name="uriString"></param> /// <returns></returns> public static string DecodeURL(String uriString) { //正则1:^(?:[\x00-\x7f]|[\xe0-\xef][\x80-\xbf]{2})+$ //正则2:^(?:[\x00-\x7f]|[\xfc-\x 阅读全文
posted @ 2011-06-20 11:57 一直在前进 阅读(748) 评论(0) 推荐(0)
利用ICSharpCode.SharpZipLib.dll生成压缩文件
摘要:ICSharpCode.SharpZipLib.dll下载: /Files/SweetGan/ICSharpCode.SharpZipLib.rar 引用之后,添加下面的方法,然后调用Zip方法就可以了。 /// <summary> /// 生成压缩文件 /// </summary> /// <param name="strZipPath">生成的zip文件的路径</param> /// <param name="strZipTopDirectoryPath">源文件的上级目录</para 阅读全文
posted @ 2011-06-02 10:18 一直在前进 阅读(1188) 评论(2) 推荐(0)
C#反射设置和读取类的属性
摘要:命名空间引入using System.Reflection;首先定义一个类public class Dog { public string DogName { get; set; } }类的实例:Dog mydog=new Dog();获取实例类型Type t = typeof(Dog);或者Type t = mydog.GetType();有了这个类型t,就可以利用反射对这个实例为所欲为了:设置属性值:t.GetProperty("DogName").SetValue(mydog, "pet", null);获取属性值:t.GetProperty(&q 阅读全文
posted @ 2011-05-19 16:30 一直在前进 阅读(926) 评论(0) 推荐(0)