Archive for 'Code Notes' Category

XML Elements or Attributes in the world

By admin - Last updated: Thursday, November 1, 2007

Elements way is good at interoperability. Attributes way is good at size of the XML. <message>      <id>1</id>      <myword>Hello</myword> </message> <message id=”1″>      <myword>Hello</myword> </message> <message id=”1″>Hello</message> <message id=”1″ myword=”Hello” /> Which way do you prefer?

C# Watch file system

By admin - Last updated: Thursday, November 1, 2007

using System.IO; public static void WatchFolder() {     FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();     fileSystemWatcher .Path = “C:\\FoldName”;     fileSystemWatcher .NotifyFilter =            NotifyFilters.LastAccess | NotifyFilters.LastWrite             | NotifyFilters.FileName | NotifyFilters.DirectoryName;     fileSystemWatcher .Filter = “*.cs”;     // Add an event […]

C# Single WinApp instance

By admin - Last updated: Thursday, November 1, 2007

using System.Threading; static void Main() {   bool isFirstInstance;   Mutex mutex =      new Mutex(true, “Global\\” + “App_Name_Here”, out isFirstInstance);   if(isFirstInstance)     Application.Run(new YourAppMainClass());   else     MessageBox.Show(”There is already an instance running.”,         “Warning”,         MessageBoxButtons.OK, MessageBoxIcon.Exclamation,         MessageBoxDefaultButton.Buttonx); }

Java simple recursion

By admin - Last updated: Monday, May 1, 2006

/**  * @author R  * 1+2+3+4 …. + 99+100 = 5050  */ public class Main {     /** Creates a new instance of Main */     public Main() {}      /**      * @param args the command line arguments      */     public static void main(String[] args)     […]

C# Microsoft Agent Control 2.0

By admin - Last updated: Wednesday, October 12, 2005

(1) Adding the MS Agent COM component in your VS.NET toolbox by clicking Visual Studio menu Tools > Add/remove toolbox items > COM Components. Tick Microsoft Agent Control. (2) The agent control will now be shown under the ‘components’ tab in the VS toolbox. If it is a windows form application, just drag and drop […]

C# Get environment info

By admin - Last updated: Monday, March 1, 2004

using System; public static void GetEnvironmentInfo() {     Console.WriteLine(”CurrentDirectory: {0}”, Environment.CurrentDirectory);     Console.WriteLine(”MachineName: {0}”, Environment.MachineName);     Console.WriteLine(”OSVersion: {0}”, Environment.OSVersion.ToString());     Console.WriteLine(”SystemDirectory: {0}”, Environment.SystemDirectory);     Console.WriteLine(”UserDomainName: {0}”, Environment.UserDomainName);     Console.WriteLine(”UserInteractive: {0}”, Environment.UserInteractive);     Console.WriteLine(”UserName: {0}”, Environment.UserName);     Console.WriteLine(”CLRVersion: {0}”, Environment.Version.ToString());     Console.WriteLine(”WorkingSet: {0}”, Environment.WorkingSet);     Console.WriteLine(”ExpandEnvironmentVariables: […]

C# Event Log

By admin - Last updated: Saturday, November 1, 2003

using System.Diagnostics; public void WriteEventLog(string appName, string logDetail) {  if (!System.Diagnostics.EventLog.SourceExists(appName))   System.Diagnostics.EventLog.CreateEventSource(appName,”Application”);   EventLog EventLog1 = new EventLog();   EventLog1.Source = appName;   EventLog1.WriteEntry (logDetail, EventLogEntryType.Error); }