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
Monday, June 30, 2008
Add Custom Words in Sharepoint Spell Checker
Today after a struggle for 15 mins, i found the solution to add up your own custom dictionary words in sharepoint. No worries now u can tell spell checker to ignore your love words.
Oh ok Back to the point.
1) Create a document library in your root site of your publishing folder ( this is where you will get your spelling feature), and give the name of the library as "Spelling".
2) Then upload a text file named “Custom Dictionary.txt”. Put your magic dictionary words separated by a single line. That is each words in each line.
There you go, do a IISRESET you are done..
DO post your comments if you find this helpful.
Add SharePoint List Items with InfoPath
So i tried many options with Infopath forms and yet amazed with its cool capabilities of quick form creation with all the form validation and also your custom Javascript code to actually submitting a form with MsXML xmlhttp request. Cool.
Ok now here is a good article written by Matt how to create a form to insert or update a sharepoint list item using its Lists.asmx webservice.
And its easy to display to show the details of your list also, its like ur OLD buggy SPD.
http://www.infopathdev.com/blogs/matt/archive/2006/02/02/Add-SharePoint-List-Items-with-InfoPath.aspx