
C#
EricYeung
这个作者很懒,什么都没留下…
展开
-
Get app path (.NET 1.1)
//generalAppDomain.CurrentDomain.BaseDirectoryEnvironment.CurrentDirectory//Get Application Full Path(EXE, DLL, Service..)System.Reflection.Assembly.GetExecutingAssembly().LocationSystem.IO.Path.GetDi原创 2007-09-21 16:25:00 · 999 阅读 · 0 评论 -
C# let textbox only accept numeric input
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e){ e.Handled = ! (char.IsDigit(e.KeyChar) || e.KeyChar.ToString() == "." || e.KeyChar == 8);}原创 2008-04-01 09:10:00 · 1328 阅读 · 1 评论 -
C# modify file (read all and modify and write all)
StringBuilder newFile = new StringBuilder();string temp = "";string[] file = File.ReadAllLines(@"C:/Documents and Settings/john.grove/Desktop/1.txt");foreach (string line in file){ if (line.Contai原创 2008-07-16 11:55:00 · 1062 阅读 · 0 评论 -
C# join DataTable (support Left/Right/Full join)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data;names原创 2008-07-16 11:52:00 · 8296 阅读 · 3 评论 -
C# 2.0 send email
private void SendMail(string smtpHost, string sender, string[] receivers, string subject, string content) { try { SmtpClient client = ne原创 2008-07-16 11:54:00 · 798 阅读 · 0 评论 -
hide insteadof close form
private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { this.Hide(); e.Cancel = true; }原创 2008-07-16 11:53:00 · 991 阅读 · 0 评论 -
Auto save UI Setting in C#
using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;using System.IO;namespace FormSetting{ class UIPersist { [D原创 2008-10-15 17:47:00 · 664 阅读 · 0 评论 -
C# use TryParseExact to convert string to date
static void Test1() { List list1 = new List(); list1.Add("2009/08/03"); list1.Add("2009/8/4"); list1.Add("2009-08-05"); list原创 2009-11-01 13:41:00 · 941 阅读 · 0 评论 -
C# download yahoo stock quote
WebClient.DownloadFile原创 2010-12-15 13:53:00 · 869 阅读 · 0 评论 -
Network Interceptor
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Net.Sockets;namespace原创 2011-10-11 22:49:10 · 697 阅读 · 0 评论 -
LINQ join and CSV read/write
class Customer { public int ID { get; set; } public string Name { get; set; } } class Order { publ原创 2011-09-30 18:35:42 · 831 阅读 · 0 评论 -
Linq in action notes (5 lang features required for LINQ)
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace LinqInAction{ class ProcessData {原创 2011-09-29 22:34:41 · 544 阅读 · 0 评论 -
Counting number of line in a file
private long CountLine(string fileName){ using(StreamReader sr = new StreamReader( new FileStream(fileName,FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) {原创 2008-04-01 09:10:00 · 861 阅读 · 0 评论 -
Return multiple dataset
// (1) OleDbDataAdapter da = new OleDbDataAdapter( "select * from jobs;select * from employee", //invalid OLE DB SQL ? "provider=Microsoft转载 2008-03-15 11:40:00 · 620 阅读 · 0 评论 -
CSharp restart program
start a new instance of the program and close the old one Process.Start(Application.ExecutablePath,Process.GetCurrentProcess().Id.ToString());this.Close();原创 2008-03-11 09:22:00 · 629 阅读 · 0 评论 -
deploy crystal report for .net 2003
deploy crystal report for .net 20031)New a setup project2)Right click project, add 4 "Merge Modules"Crystal_Database_Access2003.msmCrystal_Database_Access2003_enu.msmCrystal_Managed2003.msmCrystal_reg原创 2007-10-22 11:45:00 · 724 阅读 · 0 评论 -
C# MDI child form management
private void ShowMDIChild(Type formType){ foreach (Form f in this.MdiChildren) { if (f.GetType() == formType) { f.BringToFront(); f.WindowState = FormWindowSt原创 2007-10-22 11:43:00 · 1176 阅读 · 0 评论 -
Usd Crystal Report .NET 1.1
1) Create stored procedure2) Create Crystal report file using the stored procedure Crystal report will auto import all storedproc parameters into report parameters3) Invoke *.rpt file. configure原创 2007-10-22 11:53:00 · 880 阅读 · 0 评论 -
ADO.Net comparision of approachs of update database
1) DataAdapter + CommandBuilder generate rubbish SQL, and if no primary key in data table, it will fail2) manual construct SQL insert/update/delete not efficient, expecially in case of batch upd原创 2007-10-22 12:14:00 · 639 阅读 · 0 评论 -
C# Create Window Service (.NET 1.1)
1) add service2) add project installer //set install account this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem; this.serviceProcessInstaller1.Password =原创 2007-10-04 11:32:00 · 932 阅读 · 0 评论 -
About protected resource member in base form
ImageList of generic base form can not be protected.because when you subclass from baseform, you have get a snap shot of the imagelist,if you modify the base form imagelist afterward, the modification原创 2007-10-04 11:33:00 · 605 阅读 · 0 评论 -
C# read xml from a string and performance test
using System;using System.Data;using System.IO;using System.Xml;namespace ConsoleApplication1{ class Class1 { [STAThread] static void Main(string[] args)原创 2008-02-07 19:40:00 · 1059 阅读 · 0 评论 -
Get cruuent function name, file... (even in release build)
using System;using System.Data;using System.IO;using System.Diagnostics;namespace ConsoleApplication1{ class Class1 { [STAThread] static void Main(string[] args) {原创 2008-02-07 19:42:00 · 833 阅读 · 0 评论 -
Thread Exception Handling (Excerpt from WWW)
Exception HandlingAny try/catch/finally blocks in scope when a thread is created are of no relevance once the thread starts executing. Consider the following program:public static void Mai原创 2008-02-07 19:48:00 · 685 阅读 · 0 评论 -
Recursive delegate and state pattern (C# version)
The concept is originated from "Practise StateCharts in C++", where author use member function pointer to represent state pattern.c# version, more easy to illustrate///////////////////////////////////原创 2007-11-20 09:59:00 · 703 阅读 · 0 评论 -
NLog CSV Rolling
using NLog;using NLog.Targets;using NLog.Layouts;FileTarget target = new FileTarget(); target.FileName = "${basedir}/log.csv"; // where to store the archive files target.ArchiveFileName = "${basedir}/原创 2008-02-15 09:39:00 · 1164 阅读 · 0 评论 -
C# frequently use code snippet
// popup message modeless dialog static void PopUpMsg(string msg) { TextBox editBox = new TextBox(); editBox.ReadOnly = true; editBox.Multiline = tr原创 2011-10-27 21:16:00 · 715 阅读 · 0 评论