Monday, July 14, 2008

[C#] Scroll reset when control focused

protected override Point ScrollToControl(Control activeControl)
{
return this.AutoScrollPosition;
}

Thursday, March 6, 2008

Certificate

PRB: "System.Net.WebException. The Underlying Connection Was Closed. Could Not Establish Trust Relationship with Remote Server." Error Message When You Upgrade the .NET Framework

Tuesday, October 16, 2007

Running ASP.Net Web Server manually

Syntax: WebDev.WebServer.EXE /path: /port: /vpath:

path: location of your file to be exposed to internet
port: port to access your application/web
vpath: virtul path (e.g. http://localhost:1010/testing)


Example
WebDev.WebServer.EXE /path:D:\Web\Testing /port:2529 /vpath:/testing

Accessing this: http://localhost:2529/testing

Wednesday, September 12, 2007

[C# 2.0] How To Debug, Install, Uninstall, Run, Stop A Windows Service

using System.Diagnostics;

protected override void OnStart(string[] args)
{

#if (DEBUG)
Debugger.Launch();
#endif

}


Tips to Install/Unistall/Run/Stop Windows Service using Visual Studio
From the menu, select Tool then External Tools, and add this item.


Title: Install Service
Command: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe
Arguments:
Initial directory: $(ProjectDir)/bin/debug

Title: Uninstall Service
Command: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe
Arguments: /u
Initial directory: $(ProjectDir)/bin/debug

Title: Run Service
Command: NET.exe
Arguments: START ""
Initial directory:

Title: Stop Service
Command: NET.exe
Arguments: STOP ""
Initial directory:

Tuesday, August 7, 2007

[C#.Net] Read xml from string variable

DataSet myDS = new DataSet();

DataTable myTable = new DataTable("table1");

myTable.Columns.Add("col1", typeof(string));

myDS.Tables.Add(myTable);

string xmlData = "<XmlDS><table1><col1>Value1</col1></table1><table1><col1>Value2</col1></table1></XmlDS>";

System.IO.StringReader xmlSR = new System.IO.StringReader(xmlData);

myDS.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);

Monday, July 30, 2007

[C#.Net] Get Response Data from 3rd Party Web Service

WebRequest request;
WebResponse response;
string url = "https://www.nbdgateway.net/xmlgateway/affiliatelogin.do";

string postdata = "affiliatecode=backcheck&username=sa&password=pass&ssn=1&product=AIM";
request = WebRequest.Create(url);
request.Method = "POST";
//request.Referer = url;
request.ContentLength = postdata.Length;
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter sw;
StreamReader sr;
// post data
sw = new StreamWriter(request.GetRequestStream());
sw.Write(postdata);
sw.Close();
//get result
response = request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
textBox1.Text = result;

Sunday, July 29, 2007

[SQL] Date Functions

Syntax
DATEPART ( datepart , date )

Day of the Week
SELECT DATEPART(dw,GETDATE())

Year
SELECT DATEPART(yy,GETDATE())
SELECT DATEPART(yyyy,GETDATE())

Quarter
SELECT DATEPART(q,GETDATE())
SELECT DATEPART(qq,GETDATE())

Month
SELECT DATEPART(m,GETDATE())
SELECT DATEPART(mm,GETDATE())

Day of the Year
SELECT DATEPART(y,GETDATE())
SELECT DATEPART(dy,GETDATE())

Month Day
SELECT DATEPART(d,GETDATE())
SELECT DATEPART(dd,GETDATE())

Week
SELECT DATEPART(wk,GETDATE())
SELECT DATEPART(ww,GETDATE())

Hour
SELECT DATEPART(hh,GETDATE())

Minute
SELECT DATEPART(n,GETDATE())
SELECT DATEPART(mi,GETDATE())

Second
SELECT DATEPART(s,GETDATE())
SELECT DATEPART(ss,GETDATE())

Millisecond
SELECT DATEPART(ms,GETDATE())