C#
dasihg
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
文件重命名并输出文件名列表
public partial class frmRename: Form{List ldir;string lastPath;public frmRename(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){try{if (!Directory.Exists(t原创 2013-05-18 13:45:30 · 939 阅读 · 0 评论 -
分页控件使用方法
前台代码: .......................... 后台代码: protected void Page_Load(object sender, EventArgs e) { if (GridPager1.IsNavigating) { BindData(原创 2012-03-27 11:44:29 · 672 阅读 · 0 评论 -
多站点图片爬虫框架
调用方法: protected void Page_Load(object sender, EventArgs e) { IDatabaseDAO objBook = DAOFactory.CreateBookDAO(); string sql = string.Format("select top 1 * from BookInfo with(n原创 2012-03-12 12:10:48 · 652 阅读 · 0 评论 -
GridView 分页代码 排序代码 分页排序 隔行换色
前台:.gridview{ border:0; background-color:#ccc;/*网格颜色*/}.gridview th{ border: 0; background-color:#eee; line-height:200%;}.gridview tr{ background-colo原创 2011-09-16 11:24:57 · 1142 阅读 · 0 评论 -
位运算用例
枚举 public enum PermissionTypes : int { None = 0, 浏览 = 1, 分类管理 = 2, 文档管理 = 4, 权限管理 = 8, 全部权限 = 浏览 | 分类管理原创 2012-04-11 10:45:30 · 337 阅读 · 0 评论 -
在同一个下拉列表显示树形结构
public string ResponseTypeTree(string nid) { StringBuilder sb = new StringBuilder(); ; DataTable dt = ClassManager.GetListByParentID("0"); for (int i = 0; i原创 2012-04-09 18:20:25 · 1018 阅读 · 0 评论 -
DateTable复制表行
DataTable idt = dt.Clone(); idt.Rows.Add(dt.Rows[i].ItemArray);原创 2012-08-16 15:56:58 · 1001 阅读 · 0 评论 -
hello world 输出 olleh dlrow
string s = "Hello World"; string[] s2 = s.Split(' '); for(int j=0;j { char[] c = s2[j].ToCharArray(); int l = s2[j].Length; for (原创 2012-10-12 23:27:47 · 2861 阅读 · 0 评论 -
泛型委托+异步回调+超时机制
写法一:(泛型委托) Func albumFunC = new Func(GetCacheObject);//泛型委托 object result =albumFunC("参数值"); 写法二: (泛型委托+超时机制) Func albumFunC = new Func(GetCacheObject);/ IAsyncRe原创 2012-08-10 12:46:29 · 1299 阅读 · 0 评论 -
使用泛型的好处
C# 泛型的优点是什么呢?在公共语言运行库和C# 语言的早期版本中,通用化是通过在类型与通用基类型 Object 之间进行强制转换来实现的,泛型提供了针对这种限制的解决方案。通过创建泛型类,您可以创建一个在编译时类型安全的集合。使用非泛型集合类的限制可以通过编写一小段程序来演示,该程序利用 .NET Framework 基类库中的 ArrayList 集合类。ArrayList 是一个使用起来非常转载 2012-11-20 21:15:22 · 1350 阅读 · 1 评论 -
UDP发包收包
异步发包:public void SendData(string ip,int port,object data){ IPEndPoint ipep = new IPEndPoint(IPAdress.Parse(ip), port); UdpClient udpClient=new UdpClient(); udpClient.BeginSend(d原创 2012-11-21 10:47:32 · 3395 阅读 · 0 评论 -
c#键值对容器
StringDictionary:默认key不区分大小写 NameValueCollection:默认key区分大小写 KeyedCollection:不是键值对容器,但是比键值对容器更好用,强烈推荐命名空间using System.Collections.SpecializedSystem.Collections 命名空间包含接口和类,这些接口和类定义各种对象(转载 2012-11-21 09:52:40 · 629 阅读 · 0 评论 -
初始化随机种
Random Counter = new Random(Guid.NewGuid().GetHashCode()); 测试例子 Random Counter = new Random(Guid.NewGuid().GetHashCode()); Response.Write(Counter.Next(1, int.MaxValue))原创 2012-12-29 13:10:50 · 612 阅读 · 0 评论 -
NavigateUr l动态参数 格式化参数
NavigateUrl='原创 2012-12-29 13:13:32 · 472 阅读 · 0 评论 -
文件下载解决中文乱码
string path = "需要下载的文件路径"; if (File.Exists(path)) { if (!".zip.rar.".Contains(Path.GetExtension(path) +".")) {原创 2013-01-05 19:39:53 · 635 阅读 · 0 评论 -
去空格正则(包括全角和半角)
(\u3000|\s)(\u3000|\s)*原创 2013-03-27 21:44:48 · 1350 阅读 · 0 评论 -
GridView和DataFormatString 日期格式 精确小数点后位数
如果DataFormatString无效,请添加属性 HtmlEncode = "false"---------------------------------------DataFormatString 属性语法如下:DataFormatString="{0:格式字符串}"我们知道在DataFormatString 中的 {0}表示数据本身,而在冒号后面的格式字符串代转载 2011-09-29 14:51:23 · 5245 阅读 · 0 评论 -
ADO.net中的五个主要对象
Connection 物件 Connection 对象主要是开启程序和数据库之间的连结。没有利用连结对象将数据库打开,是无法从数据库中取得数据的。这个物件在ADO.NET的最底层,我们可以自己产生这个对象,或是由其它的对象自动产生。Command 物件 Command 对象主要可以用来对数据库发出一些指令,例如可以对数据库下达查询、新增、修改、删除数据等指令,以及呼叫存在数转载 2013-05-11 14:23:13 · 687 阅读 · 0 评论 -
Excel组件NPOI操作类
using System;using System.Collections.Generic;using System.Linq;using System.Text;using NPOI.SS.UserModel;using System.IO;using System.Data;using NPOI.HSSF.UserModel;using System.Colle原创 2013-05-11 15:00:12 · 3930 阅读 · 0 评论 -
冒泡排序
#include void bubbleSort(intarr[],intcount){ inti = count, j; inttemp; while(i > 0) { for(j = 0; j { if(arr[j] > arr[j + 1]) {转载 2013-05-11 15:34:16 · 498 阅读 · 0 评论 -
1,1,2,3,5,8算法
int method(int i) { if (i == 1 || i==2) return 1; else return method(i-1) + method(i - 2); }原创 2013-04-09 20:02:54 · 662 阅读 · 0 评论 -
单例模式代码示例
双重锁机制namespace Singleton { public class Singleton { //定义一个私有的静态全局变量来保存该类的唯一实例 private static Singleton singleton; //定义一个只读静态对象转载 2013-05-11 16:09:27 · 689 阅读 · 0 评论 -
Page_Load基类,重写OnLoad
protected override void OnLoad(EventArgs e) { userid = PublicFun.GetSessionValue(HttpContext.Current.Session, "member_id", 0);//前台用户 if (userid == 0) {原创 2013-07-12 10:20:32 · 1681 阅读 · 0 评论 -
缓存管理公用类(通过委托更新缓存)
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web; namespace Cache{ public class IListCache { public delegate IList原创 2012-12-29 13:24:46 · 593 阅读 · 0 评论 -
利用反射将Datatable、SqlDataReader转换成List模型
1. DataTable转IListpublic class DataTableToListwhereT :new(){//////利用反射将Datatable转换成List模型/////////public static List ConvertToList(DataTabledt){List list =newList();Typetype原创 2013-05-18 13:51:10 · 5401 阅读 · 0 评论 -
OUTPUT新增记录入库示例C#+存储过程
2.存储过程 public int Insert(CebContractData model) { var parameters = new SqlParameter[] { new SqlParameter("@ID",SqlDbType.Int){Value = mo原创 2013-07-15 15:08:01 · 587 阅读 · 0 评论 -
获取浏览器类型
public static int getBrowser() { string BrowserInfo = HttpContext.Current.Request.UserAgent; if (BrowserInfo.Contains("MSIE 7.0")) {//IE7 return 1; } else if (BrowserInfo.Contains("MSIE转载 2013-07-02 15:44:53 · 596 阅读 · 0 评论 -
序列化泛型 反序列化JSON
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Web.Script.Serialization;usingSystem.Reflection;usingSystem.Data;namespace Business.Util{p原创 2013-05-18 13:48:51 · 2513 阅读 · 0 评论 -
ASP.NET获取根目录的方法集合
编写程序的时候,经常需要用的项目根目录,自己总结如下: 1、取得控制台应用程序的根目录方法 方法1、Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法2、AppDomain.CurrentDomain.BaseDirectory 获取基目录,它由程序集冲突解决程序用来探测程序集 2、取得Web应用程序的根目录转载 2013-07-05 14:45:02 · 1724 阅读 · 0 评论 -
返回List的分页方法
cs代码 /// /// 处理分页检索存储过程(SQL2005) /// /// 需要查询的字段 /// 表名 /// sql条件 /// 排序字符串 /// 当前页 /// 每页记录数 /// 总记录数原创 2013-11-12 13:55:35 · 1174 阅读 · 0 评论 -
使用Application_Error捕获站点错误并写日志
Global.ascx页面使用以下方法即可捕获应用层没有try cath的错误 protected void Application_Error(Object sender, EventArgs e) { //在出现未处理的错误时运行的代码 Exception ex = Server.GetLastErro原创 2013-12-25 10:59:31 · 2910 阅读 · 0 评论 -
WebControl(DataGrid/GridView)导出Excel、Word
/// /// /// /// /// /// 编码 public static void OutExcel(System.Web.UI.WebControls.WebControl dg, string name, string bm) {原创 2012-03-26 10:37:49 · 487 阅读 · 0 评论 -
flashpaper使用详解
以下功能经多次测试均不能在Server2003上运行,须改用winform或服务程序且使用超级管理员登陆方可进行转换 1、调用代码(C#) /// /// 将pdf/doc/excel等转换为swf文件 /// /// 源文件 /// 目标文件 /// public Boolean Src2Swf(string S原创 2011-11-28 12:19:12 · 4795 阅读 · 9 评论 -
C# 图片加水印
using System;using System.IO;using System.Collections;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Ima转载 2011-09-21 15:04:58 · 684 阅读 · 0 评论 -
小文件上传代码
前台:上传图片 后台: protected void Upfile_Click(object sender, EventArgs e) { HttpPostedFile hpf = oFile.Posted原创 2011-09-20 14:31:53 · 587 阅读 · 0 评论 -
页面编码总结
1. 脚本形式:function (){alert('')} 单引号之间的内容必须将 '转为\'转换代码:reval = reval.Replace("'", "\\'");形式:function (){alert("") 双引号之间的内容必须将 "转为原创 2011-09-28 16:43:46 · 726 阅读 · 0 评论 -
动态添加用户控件(usercontrol)
int aid = Sxmobi.Tools.GetRequestVal("aid", -1); Page page = (Page)HttpContext.Current.Handler; VP2Admin.UC.AlbumS原创 2011-10-09 18:53:18 · 1201 阅读 · 0 评论 -
从WebResponse获取源文件名、扩展名
static string GetFilenameFromResponse(WebResponse wr, string defaultFilename) { string desc = wr.Headers["Content-Disposition"]; if (desc != null) {原创 2011-11-15 10:37:06 · 3223 阅读 · 0 评论 -
Net 防刷新提交
if (Request.Headers["Accept"] == "*/*") return;//防刷新原创 2011-10-27 16:22:25 · 336 阅读 · 0 评论 -
解决IFrame下无法写Cookie问题
HttpContext.Current.Response.AddHeader("P3P", "CP=CAO PSA OUR"); HttpContext.Current.Response.Cookies["homeid"].Value = val; HttpContext.Current.Response.Cookies["homei原创 2011-10-27 16:23:42 · 3951 阅读 · 0 评论
分享