Tuesday, December 30, 2008

C# DateTime Format String

  1. Standard Format String

    d: 12/30/2008
    D: Tuesday, December 30, 2008
    f: Tuesday, December 30, 2008 5:53 PM
    F: Tuesday, December 30, 2008 5:53:15 PM
    g: 12/30/2008 5:53 PM
    G: 12/30/2008 5:53:15 PM
    m: December 30
    o: 2008-12-30T17:53:15.0932357-05:00
    R: Tue, 30 Dec 2008 17:53:15 GMT
    s: 2008-12-30T17:53:15
    t: 5:53 PM
    T: 5:53:15 PM
    u: 2008-12-30 17:53:15Z
    U: Tuesday, December 30, 2008 10:53:15 PM
    y: December, 2008


  2. Custom Format String

    Year
    %y: 8
    yy: 08
    yyy: 2008
    yyyy: 2008

    Month
    %M: 12
    MM: 12
    MMM: Dec
    MMMM: December

    Day
    %d: 30
    dd: 30
    ddd: Tue
    dddd: Tuesday

    Hour
    %h: 5
    hh: 05
    hhh: 05
    hhhh: 05
    %H: 17
    HH: 17
    HHH: 17
    HHHH: 17

    Minute
    %m: 53
    mm: 53
    mmm: 53
    mmmm: 53
    Second
    %s: 15
    ss: 15
    sss: 15
    ssss: 15

    Millisecond
    %f: 0
    ff: 09
    fff: 093
    ffff: 0932
    %F:
    FF: 09
    FFF: 093
    FFFF: 0932

    Kind
    %K: -05:00
    KK: -05:00-05:00
    KKK: -05:00-05:00-05:00
    KKKK: -05:00-05:00-05:00-05:00

    TimeZone
    %z: -5
    zz: -05
    zzz: -05:00
    zzzz: -05:00

    Other
    %g: A.D.
    gg: A.D.
    ggg: A.D.
    gggg: A.D.
    %t: P
    tt: PM
    ttt: PM
    tttt: PM

  3. Standard Format string to Custom Format string mapping

    Year Month Day Patterns
    d: MM/dd/yyyy
    D: dddd, dd MMMM yyyy
    M or m: MMMM dd
    Y or y: yyyy MMMM

    Time Patterns
    t: HH:mm
    T: HH:mm:ss

    Year Month Day and Time without Time Zones
    f: dddd, dd MMMM yyyy HH:mm
    F: dddd, dd MMMM yyyy HH:mm:ss
    g: MM/dd/yyyy HH:mm
    G: MM/dd/yyyy HH:mm:ss

    Year Month Day and Time with Time Zones
    o: yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
    R or r: ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
    s: yyyy'-'MM'-'dd'T'HH':'mm':'ss
    u: yyyy'-'MM'-'dd HH':'mm':'ss'Z'
    U: dddd, dd MMMM yyyy HH:mm:ss

More details in Kathy Kam's blog: http://blogs.msdn.com/kathykam/archive/2006/09/29/.NET-Format-String-102_3A00_-DateTime-Format-String.aspx

Thursday, December 18, 2008

Visual C# IDE Shortcuts

  1. (Ctrl + K + C) - Comment out the selected Lines
  2. (Ctrl + K + U) - Uncomment the selected lines
  3. (F12) - Go to definition
  4. (Shift +F12) - Find all reference
  5. (Ctrl + Shift + B) - Build Solution
  6. (F5) - Start debuging
  7. (Ctrl + F5) - Start without debuging
  8. (F10) - Step Over
  9. (F11) - Step In
  10. (F9) - Toggle breakpoints
  11. (Ctrl + Shift + F9) - Delete all breakpoints

Encode & Decode

Base64

  • Encode:
    string encodedData = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(originalData));
  • Decode:
    string decodedData = System.Text.Encoding.ASCII.GetString(Convert.FromBase64String(originalData));

Url

  • Encode:
    string encodedData = System.Web.HttpUtility.UrlEncode(originalData);
  • Decode:
    string decodedData = System.Web.HttpUtility.UrlDecode(originalData);

HTML

  • Encode:
    string encodedData = System.Web.HttpUtility.HTMLEncode(originalData);
  • Decode:
    string decodedData = System.Web.HttpUtility.HTMLDecode(originalData);

Wednesday, December 17, 2008

Create Proxy class from WSDL file manually

  1. Save the wsdl file.
  2. Use wsdl.exe tool in the fold - C:\Program files\Microsoft Visual Studio 8\SDK\v2\Bin
    command: wsdl.exe my.wsdl /out:myproxy.cs

Row count of SqlDataSource

Use the Selected event on the SqlDataSource and get the Affected Rows from it.

protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
int total_count = e.AffectedRows;
}