Thursday, November 27, 2008

Printing Date in different formats

DateTime.ToString()
Assume dt is a datetime object.
dt.ToString("MM/dd/yyyy") prints 05/05/2005
In the same way, try out the following options.

0 MM/dd/yyyy 05/05/2005
1 dddd, dd MMMM yyyy Thursday, 05 May 2005
2 dddd, dd MMMM yyyy HH:mm Thursday, 05 May 2005 06:30
3 dddd, dd MMMM yyyy hh:mm tt Thursday, 05 May 2005 06:30 AM
4 dddd, dd MMMM yyyy H:mm Thursday, 05 May 2005 6:30
5 dddd, dd MMMM yyyy h:mm tt Thursday, 05 May 2005 6:30 AM
6 dddd, dd MMMM yyyy HH:mm:ss Thursday, 05 May 2005 06:30:07
7 MM/dd/yyyy HH:mm 05/05/2005 06:30
8 MM/dd/yyyy hh:mm tt 05/05/2005 06:30 AM
9 MM/dd/yyyy H:mm 05/05/2005 6:30
10 MM/dd/yyyy h:mm tt 05/05/2005 6:30 AM
10 MM/dd/yyyy h:mm tt 05/05/2005 6:30 AM
10 MM/dd/yyyy h:mm tt 05/05/2005 6:30 AM
11 MM/dd/yyyy HH:mm:ss 05/05/2005 06:30:07
12 MMMM dd May 05
13 MMMM dd May 05
14 yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2005-05-05T06:30:07.7199222-04:00
15 yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK 2005-05-05T06:30:07.7199222-04:00
16 ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Thu, 05 May 2005 06:30:07 GMT
17 ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Thu, 05 May 2005 06:30:07 GMT
18 yyyy'-'MM'-'dd'T'HH':'mm':'ss 2005-05-05T06:30:07
19 HH:mm 06:30
20 hh:mm tt 06:30 AM
21 H:mm 6:30
22 h:mm tt 6:30 AM
23 HH:mm:ss 06:30:07
24 yyyy'-'MM'-'dd HH':'mm':'ss'Z' 2005-05-05 06:30:07Z
25 dddd, dd MMMM yyyy HH:mm:ss Thursday, 05 May 2005 06:30:07
26 yyyy MMMM 2005 May
27 yyyy MMMM 2005 May

The patterns for DateTime.ToString ( 'd' ) :
0 MM/dd/yyyy 05/05/2005

The patterns for DateTime.ToString ( 'D' ) :
0 dddd, dd MMMM yyyy Thursday, 05 May 2005

The patterns for DateTime.ToString ( 'f' ) :
0 dddd, dd MMMM yyyy HH:mm Thursday, 05 May 2005 06:30
1 dddd, dd MMMM yyyy hh:mm tt Thursday, 05 May 2005 06:30 AM
2 dddd, dd MMMM yyyy H:mm Thursday, 05 May 2005 6:30
3 dddd, dd MMMM yyyy h:mm tt Thursday, 05 May 2005 6:30 AM

The patterns for DateTime.ToString ( 'F' ) :
0 dddd, dd MMMM yyyy HH:mm:ss Thursday, 05 May 2005 06:30:07

The patterns for DateTime.ToString ( 'g' ) :
0 MM/dd/yyyy HH:mm 05/05/2005 06:30
1 MM/dd/yyyy hh:mm tt 05/05/2005 06:30 AM
2 MM/dd/yyyy H:mm 05/05/2005 6:30
3 MM/dd/yyyy h:mm tt 05/05/2005 6:30 AM

The patterns for DateTime.ToString ( 'G' ) :
0 MM/dd/yyyy HH:mm:ss 05/05/2005 06:30:07

The patterns for DateTime.ToString ( 'm' ) :
0 MMMM dd May 05

The patterns for DateTime.ToString ( 'r' ) :
0 ddd, dd MMM yyyy HH':'mm':'ss 'GMT' Thu, 05 May 2005 06:30:07 GMT

The patterns for DateTime.ToString ( 's' ) :
0 yyyy'-'MM'-'dd'T'HH':'mm':'ss 2005-05-05T06:30:07

The patterns for DateTime.ToString ( 'u' ) :
0 yyyy'-'MM'-'dd HH':'mm':'ss'Z' 2005-05-05 06:30:07Z

The patterns for DateTime.ToString ( 'U' ) :
0 dddd, dd MMMM yyyy HH:mm:ss Thursday, 05 May 2005 06:30:07

The patterns for DateTime.ToString ( 'y' ) :
0 yyyy MMMM 2005 May

Building a custom DateTime.ToString Patterns
The following details the meaning of each pattern character. Not the K and z character.

d Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd Represents the full name of the day of the week (Monday, Tuesday etc)
h 12-hour clock hour (e.g. 7)
hh 12-hour clock, with a leading 0 (e.g. 07)
H 24-hour clock hour (e.g. 19)
HH 24-hour clock hour, with a leading 0 (e.g. 19)
m Minutes
mm Minutes with a leading zero
M Month number
MM Month number with leading zero
MMM Abbreviated Month Name (e.g. Dec)
MMMM Full month name (e.g. December)
s Seconds
ss Seconds with leading zero
t Abbreviated AM / PM (e.g. A or P)
tt AM / PM (e.g. AM or PM
y Year, no leading zero (e.g. 2001 would be 1)
yy Year, leadin zero (e.g. 2001 would be 01)
yyy Year, (e.g. 2001 would be 2001)
yyyy Year, (e.g. 2001 would be 2001)
K Represents the time zone information of a date and time value (e.g. +05:00)
z With DateTime values, represents the signed offset of the local operating system's time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6)
zz As z but with leadin zero (e.g. +06)
zzz With DateTime values, represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes. (e.g. +06:00)
f Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
ff Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.
fff Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
ffff Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffff Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
ffffff Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
fffffff Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds.
F Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero.
: Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds.
/ Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days.
" Represents a quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Your application should precede each quotation mark with an escape character (\).
' Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters.
%c Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers.

Friday, May 30, 2008

Regular Expression that accepts 0-9,space,/,+,- only

^([0-9][\ ][\/][\+][\-])*$

The below link can be used to test your regular expressions:
http://www.dotnetcoders.com/web/Learning/Regex/RegexTester.aspx

Calling a web-service

Here I am not concerned about creating a web-service & consuming it. I hope you know this already. But sometimes when you consume the web-service in .NET it throws an exception like 'The request failed with HTTP status 401 : unauthorized'. When you try to run the web-service directly, it runs without fail.


Resolution:

Dim obj As New basicops.operations
obj.Credentials = System.Net.CredentialCache.DefaultCredentials

lblResult.Text = "Result: " & obj.Subtract(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)).ToString()

Thursday, April 24, 2008

What happens when an asp.net page is requested from the browser

From the browser the request is sent to IIS. There is an aspnet_isapi.dll in IIS that takes care of serving the request. From this it sends the request to .net framework's worker process. (aspnet_wp.exe)

From IIS there is a mapping that specifies the which isapi is going to process that page. From the website properties, From virtual directory tab, click on 'configuration' button. This shows the application configuration window.



At its core, the ASP.NET execution engine compiles the page into a class, which derives from the code behind class (which in turn derives directly or indirectly from the Page class). Then it injects the newly created class into the execution environment, instantiates it, and executes it.

Sunday, April 20, 2008

Crystal Reports in ASP.NET

using CrystalDecisions.CrystalReports.Engine;
-----------------------------------------------------------------------------

ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath("rptOne.rpt"));

for (int index = 0; index < rptDoc.Database.Tables.Count; index++)
{
rptDoc.Database.Tables[index].LogOnInfo.ConnectionInfo.ServerName = "BHARATIKUMAR";
rptDoc.Database.Tables[index].LogOnInfo.ConnectionInfo.DatabaseName = "Employee";
rptDoc.Database.Tables[index].LogOnInfo.ConnectionInfo.UserID = "kumar";
rptDoc.Database.Tables[index].LogOnInfo.ConnectionInfo.Password = "kumar";
rptDoc.Database.Tables[index].ApplyLogOnInfo(rptDoc.Database.Tables[index].LogOnInfo);
}


crvOne.ReportSource = rptDoc;

crvOne.DataBind();

Thursday, April 10, 2008

Posting to my blog after a very long time

Hi everyone,

In my office, firewall do blocks blogger.com website. Hence couldnt login & couldnt paste to my blog. After 8 months this is the first time I am logging into my blogger.

I am into a production support & enhancement project now. Going to work on MCMS 2002 (Microsoft Content Management Server 2002). I hope MCMS is interesting.

:-) Will keep posting stuff on MCMS from now onwards.