Wednesday, April 19, 2006

Convert String to Date and check Date Validation on Server side in C#.Net.

Convert String to Date and check Date Validation on Server side in C#.Net.

There are lots of functions available in client side for date validation.
Sometime server side date validation function require
It’s very simple but require much time to right. (C#.Net)

SupportedDateFormats : It is a customise function where you can refer the date format whatever you want.

ConvertStringToDate : This will return True or Flase based on date format supported. And give converted Date from String.

public static bool ConvertStringToDate(string dateString, ref DateTime resultDate)
{
try
{
resultDate = DateTime.ParseExact(
dateString,
SupportedDateFormats(),
System.Globalization.CultureInfo.CurrentCulture,
System.Globalization.DateTimeStyles.None
);
return true;
}
catch
{
return false;
}
}

//This is custom defined format function you can add more date format as per your requirement
like "dd/MM/YYYY", etc in the allFormats array
private static string[] SupportedDateFormats()
{
string[] allFormats = new string[] {
"MM/dd/yyyy",
"MM/dd/yy",
"M/d/yy",
"MM/d/yy",
"M/dd/yy",
"M/d/yyyy",
"MM/d/yyyy",
"M/dd/yyyy"};
return allFormats;
}

// Now you can use this function in your code like this
private void button1_Click(object sender, EventArgs e)
{
DateTime dtTemp;
dtTemp =DateTime.Today.Date;
lblIsvalidDate.Text =
ConvertStringToDate(
textBox2.Text,
ref dtTemp
).ToString();
lblCovertedDate = dtTemp.ToString();
}

Note:
If you want this code in VB.Net I would like to tell you very good site that will

Different between lifecycle of Windows services and Standard EXE

Different between lifecycle of Windows services and Standard EXE

"Windows services" lifecycle is managed by "Service Control Manager" which is responsible for starting and stopping the service and the applications do not have a user interface or produce any visual output. Windows services are ideal for use in server environments or need long-running applications/functionality. Any user messages are typically written to the Windows Event Log. Windows Services can be automatically started when the computer is booted.

"Standard executable" doesn't require Control Manager and is directly related to the visual output

Happy coding ....
Arti Gupta

Nucleus Software , Noida

Tuesday, April 18, 2006

Strong type Vs Weak type and Debug build Vs Release build

Strong type Vs Weak type and Debug build Vs Release build
Simple way to remember different between these type and build
Strong type: Checking the types of variables at compile time
Weak type: Checking the types of variables at run time.
Strong type is checking the types of variables as soon as possible, usually at compile time. While weak typing is delaying checking the types of the system as late as possible, usually to run-time. Which is preferred depends on what you want. For scripts & quick stuff you’ll usually want weak typing, because you want to write as much less code as possible. In big programs, strong typing can reduce errors at compile time.
Debug build: Code can debugged, containing debug symbol (.pdb file)
Release build: Code can not debugged, it contain debug symbol
Debug build contain debug symbols and can be debugged while release build doesn’t contain debug symbols, doesn’t have [Conational (”DEBUG”)] methods calls compiled, can’t be debugged, less checking, etc. There should be a speed difference, because of disabling debug methods, reducing code size etc but that is not a guarantee (at least not a significant one)

Ritesh Kesharwani

Infosys,Pune




Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1¢/min.

Wednesday, April 12, 2006

How to Add Custom Tag in Web.Config Page (ASP.NET)

How to Add Custom Tag in Web.Config Page (ASP.NET)
To add a custom tag to Web.config you need to first explicitly specify the new tag name in Web.config via the <configSections> tag
For Example:

<configuration>

<configSections>

<section name="MyAppSettings"
type="System.Configuration.NameValueFileSectionHandler,
System, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />

</configSections>
...
</configuration>

This <section ... /> tag indicates that we are going to be adding New tag named MyAppSettings.
Now we can add a <MyAppSettings> tag to our Web.config file and
add <add ... /> tags to add application-wide parameters,
For Example:

<configuration>

<configSections>

<section name="MyAppSettings"
type="System.Configuration.NameValueFileSectionHandler,
System, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
</configSections>

<MyAppSettings>
<add key="connString" value="connection string" />
</MyAppSettings>
...
</configuration>
How to Read Custom Tag

To read this custom value from an ASP.NET Web page we use the following syntax:

ConfigurationSettings.GetConfig("MyAppSettings")("connString")


Ritesh Kumar Kesharwani
Infosys,Pune

Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.
Great rates starting at 1¢/min.