Tuesday, July 29, 2008
Dataformwebpart Server variables
http://dataformwebpart.com/2007/11/07/spd-2007-data-view-parameters-you-dont-know-about/
Thursday, July 10, 2008
Get Current User Email, Login, Display Name Details
The normal code which microsoft given fails:
SPWeb site = SPContext.Current.Web;Because most of the users who don't have access to All sites won't give details of their email by the code given. If you are wondering what is all about the difference between All users see below:
SPUser user = site.CurrentUser;
string DisplayName = user.Name;
string Login = user.LoginName;
string EMail = user.Email;
string User Notes = user.Notes;
SPWeb site = SPContext.Current.Web;The code gives 3 types of different user collection so i guess the user who logged in and didn't find his email by the code above belongs to one of this group.
SPUserCollection c1 = site.Users;
SPUserCollection c2 = site.AllUsers;
SPUserCollection c3 = site.SiteUsers;
The difference between these SPUserCollection is copied from MSDN.:
I used a basic way to get the current user using (context of control HTTPCONTEXT) Context.User.Identity.Name or Page.User.Identity.Name which does the same httpcontext.
After we get the current user login i can pass it to the magic of another Class in sharepoint object Model which brings the user details.
using Microsoft.SharePoint.Utilities;
SPWeb osite = SPContext.Current.Web;
SPPrincipalInfo prin = SPUtility.ResolvePrincipal(osite,Context.User.Identity.Name , SPPrincipalType.All, SPPrincipalSource.All, osite.AllUsers, false);
writer.Write(prin.Email);
using this method u can also search the user by their Email ID, or their Display name. its a cool method who does the search on multiple fields.
Tuesday, July 1, 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. <tr> <td><%# DataBinder.Eval(Container.DataItem, "field1") %></td> <td><%# DataBinder.Eval(Container.DataItem, "field2") %></td> </tr> </ItemTemplate>
Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:
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>
Thread Safe .NET Event Technique
public event EventHandler Updated = delegate { };
protected void UpdatePrice(string mySymbol, decimal newPrice, long newVolume)
{
_priceList[mySymbol] = newPrice;
_volumeList[mySymbol] = newVolume;
Updated(this, new MarketFeedEventArgs(mySymbol, newPrice, newVolume));
}
Because in case of multithreaded environment if the event updated is not subscribed or if null it. Removes the subscription from all the other event handler. So instead of making a new copy of event each time, we should initialize the events at the first case.
People normally use like this which is performance friendly but not good practice for multithreaded environ
public event EventHandler Updated;
protected void UpdatePrice(string mySymbol, decimal newPrice, long newVolume)
{
_priceList[mySymbol] = newPrice;
_volumeList[mySymbol] = newVolume;
if(Updated != null)
Updated(this, new MarketFeedEventArgs(mySymbol, newPrice, newVolume));
}
How to check email works without using SMTP
You can find your mails posted in the directory mentioned below after you send a mail by code.
<system.net>
<mailsettings><smtp deliverymethod="SpecifiedPickupDirectory"> <specifiedpickupdirectory pickupdirectorylocation="c:\Test\">
</smtp>
</mailsettings>
</SYSTEM.NET>
Source of this tip : http://dotnettipoftheday.org/tips/smtp-delivery-methodSpecifiedPickupDirectory.aspx