Sunday, February 17, 2008

Use explicit casting instead of DataBinder.Eval

The DataBinder.Eval method uses .NET reflection to evaluate the arguments that are passed in and to return the results. Consider limiting the use of DataBinder.Eval during data binding operations in order to improve ASP.NET page performance.
Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "field1") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "field2") %></td>
</tr>
</ItemTemplate>


Using explicit casting offers better performance by avoiding the cost of .NET reflection. Cast the Container.DataItem as a DataRowView:


<ItemTemplate>

<tr>
<td><%# ((DataRowView)Container.DataItem)["field1"] %></td>
<td><%# ((DataRowView)Container.DataItem)["field2"] %></td>
</tr>
</ItemTemplate>


Referenced by http://dotnettipoftheday.org/tips/use-explicit-casting-instead-of-databinder.eval.aspx?discussion=1

Wednesday, February 6, 2008

How to check email works without using SMTP

Testing code that sends email has always been a pain. You had to set up a SMTP service just to test that your .NET application sends the e-mail correctly.

However, there is a way to send e-mails with no SMTP server set up. Just configure your .NET application to drop e-mails into a specified folder instead of sending them via SMTP server:

<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Test\" />
</smtp>
</mailSettings>
</system.net>

This will instruct SmtpClient class to generate mail message, save it as .eml file and drop it into c:\Test\ folder.

Referenced by http://dotnettipoftheday.org/tips/smtp-delivery-method-SpecifiedPickupDirectory.aspx



Tuesday, February 5, 2008

SharePoint Technologies

SharePoint is a family of technologies from Microsoft that provides a server infrastructure to support the needs of information workers and their employers. SharePoint makes it possible for companies to engage all their information workers through the tools people are using already - Office clients (such as Word and Excel), Internet browsers (such as Internet Explorer), and e-mail clients (such as Outlook). Obviously, SharePoint works best with Office 2007.


SharePoint also provides workers with the ability to connect with each other. Instead of sending files back and forth via e-mail, workers can set up information environments that make it easy to collaborate on documents or share a calendar. SharePoint uses a Web site infrastructure to deliver the bulk of its features. Users can use a Web browser or familiar Office clients, such as Word and Excel, to access SharePoint’s features. Office clients enable information workers to use familiar tools in new ways, which reduces training and support costs and increases solution development opportunities.


SharePoint isn’t a new technology. The ability to provision team sites for use with Office clients was first introduced in May 2001 with a product called SharePoint Team Services. SharePoint Portal Server 2001, a product for connecting team sites, was released in June 2001. With each subsequent release, more and more features were added. Windows SharePoint Services (WSS) version 3, which was released in November 2006, represents a major re-architecting of the product.

Starting with the 2003 release, WSS became a component of the Windows Server operating system. The portal product, SharePoint Portal Server 2003, released alongside Office 2003. The latest release, Microsoft Office SharePoint Server (MOSS) 2007, is now officially part of the Microsoft Office suite of products.

excerpt from Microsoft Sharepoint 2007 for Dummies book.

Saturday, February 2, 2008

Correct using of ASP.NET Cache

Often in ASP.NET application we see a code which looks like this one:
if (Cache["SomeData"] != null)
{
string name = ((SomeClass)Cache["SomeData"]).Name;
//.....
}
This code is not safe enough and the second statement can generate a NullReferenceException sometimes. There is no guaranttee that a cached object will stay in the cache between two calls. After the first call it can be deleted either by garbage collector or by another thread to refresh cached data.
So to overcome this problem rewrite the code using as operator:
SomeClass someClass = Cache["SomeData"] as SomeClass;
if (someClass != null)
{
string name = someClass.Name;
//.....
}



Referenced by http://dotnettipoftheday.org/tips/correct-using-of-aspnet-cache.aspx