Friday, May 30, 2008

convert an amount value in Words

Hi ,
Now we have a function in our sql database which can convert an amount value to its "in words " equivalent ..
just as you do while signing cheques ....
how to use ?select dbo.util_fn_AmountToWords(456.75)
will give u and output of:"Four Hundred And Fifty Six And Seventy Five Paise"

Wednesday, May 28, 2008

To fetch data from gridview to Excel/Doc

private void Export(GridView GridView1) { System.IO.StringWriter sw = new StringWriter(); System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw); HtmlForm frm = new HtmlForm(); Response.ContentType = "application/vnd.ms-excel" ; Response.AddHeader("content-disposition", "attachment;filename=SomeFile.doc"); Response.Charset = "" ; EnableViewState = false ; Controls.Add(frm) ; frm.Controls.Add(GridView1); frm.RenderControl(htw) ; Response.Write(sw.ToString()) ; Response.End() ; }

Saturday, May 24, 2008

Fetching User Phone number from active directory.

protected void Page_Load(object sender, EventArgs e)
{
string path = "LDAP://"; // Path for active directory.
System.DirectoryServices.DirectoryEntry de = new System.DirectoryServices.DirectoryEntry(path);
System.DirectoryServices.DirectorySearcher deSearch = new System.DirectoryServices.DirectorySearcher(de);
deSearch.PropertiesToLoad.Add("mail");
deSearch.PropertiesToLoad.Add("telephoneNumber");
string strUserName = System.Web.HttpContext.Current.User.Identity.Name;
strUserName = strUserName.Remove(0, 10);
deSearch.Filter = ("(sAMAccountName= " + strUserName + ")");
deSearch.SearchScope = SearchScope.Subtree;
SearchResult results = deSearch.FindOne();
TextBox1.Text = results.Properties["mail"][0].ToString();
if ((results.Properties["telephoneNumber"].Count != 0))
{
TextBox1.Text = results.Properties["telephoneNumber"][0].ToString();
}
else
{
Response.Write("Error: There is no entry in telephoneNumber field of the Active Directory for the current user");
}

}