Wednesday, March 14, 2007

Date formatting

Some of the formats for date formatting.
specifier type output
dd Day 08
ddd Short Day Name Mon
dddd Full Day Name Monday
hh 2 digit hour 12
HH 2 digit hour (24 hour) 12
mm 2 digit minute 30
MM Month 06
MMM Short Month name Jun
MMMM Month name June
ss seconds 59
tt AM/PM PM
yy 2 digit year 70
yyyy 4 digit year 1970
: seperator, e.g. {0:hh:mm:ss} 12:30:59
/ seperator, e.g. {0:dd/MM/yyyy} 08/06/1970

Can simply be used with string as well.
for example,
string date=DateTime.Now.ToString("yyyy");

In some controls there is a DataFormatString property as well:
DataFormatString="{0:g}"

Thursday, March 1, 2007

TransactionScope

While developing applications we often need to handle transactions. Before .NET 2 various options were available like ADO.NET Transaction model, Enterprise Services Transactions etc but the new TransactionScope has really made it easy to manage transactions.
With transactions scope we can do transactions across multiple application layers as well as the distributed ones.
The good news is that System.Transactions has the unique capability of knowing whether to use a distributed or lightweight transaction. It will use a lightweight transaction if there is a single domain accessing a single database, or it will use a distributed transaction similar to the enterprise services transaction model if there are multiple databases to access.

To use this new transaction functionality we need to add the namespace System.Transactions.

To use the TransactionScope we can simply add it in a using block like this


using (TransactionScope ts = new TransactionScope())
{
// code goes here
//and once we are done to complete the transaction
ts.Complete();

}

Different options are available with TransactionScope which could be exploited according to needs.

One thing to be taken into consideration is that if applications or components involved in a transaction are not residing on the same machine we need to do some settings else an exception like the given below could be raised.

{"The transaction has already been implicitly or explicitly committed or aborted."}
System.Transactions.TransactionException: {"The transaction has already been implicitly or explicitly committed or aborted."}

To overcome this problem we need to set up MSDTC in both the systems.

Setup both the systems to allow transactions by following these steps

• Open the Control Panel and select Administrative Tools.
• From Administrative Tools select Component Services.
• Open the Component Services tree to display My Computer.
• Right click My Computer and select properties to display the properties dialog.
• In the dialog select the MSDTC tab and click the Security Configuration button.
• In the Security Configuration dialog, make sure Allow Inbound, Allow Outbound and No Authentication Required are selected.

Considering an application running on Win2003 and communicating with SQL server on a machine with Win2k there are not security setting required for Win2k. In that case “No Authentication Required” should be selected on the application server.

For more details on Transactions: http://msdn2.microsoft.com/en-us/library/w97s6fw4.aspx

Thursday, February 22, 2007

Microsoft TechDays 2007

I recently got the opportunity to attend Microsoft TechDays 2007 held in Paris, France. The main objective of the occasion was to gather all the events like DevDays, Student days etc and organize an event which would address all the people including developers, architects, students, entrepreneurs etc.
The event lasted for 3 days with many industry stands as well more than 250 sessions on different technologies. The event was attended by a large tech community and overall it was a great success for Microsoft. The event gave an overall view of the new trends in technology especially Windows Vista, .NET 3 etc.
I found that event really interesting and informative and hope that Microsoft would continue to organize events of that sort.

TechDays Blog:
http://blogs.technet.com/mstechdays/archive/2007/02/12/inside-the-microsoft-techdays-r-capitulatif-des-vid-os-disponibles-en-ligne.aspx

Open blank page from ASP.NET Menu

I recently had this issue of opening a blank page through ASP.NET menu using treeview and sitemap. Apparently there is no easy option of doing it. But with a little bit of trick this could be achieved.
To open a blank page using a sitemap we can add a javascript in the url attribute of sitemap note.

An example:

A node by clicking which the blank page should be opened.

sitemapnode title="Proc├ędures" description="Proc├ędures" url="javascript:OpenBlankPage();"


and in the javacript function
function OpenBlankPage() {
window.open('site url here');
return;
}
Javascript could directly be added in the url as well.
Voila a small tip which could save you some time.