Thursday, July 18, 2013

How to get username from email address c#

Here is sample code snippet that I have used to get username from the email address. You can use MailAddress Class to get few built in properties for our use.

   1: string FromEmail = ConfigurationManager.AppSettings["NotifyEmail"].ToString();
   2: MailAddress FromAddress = new MailAddress(FromEmail);
   3: objEmail.From = FromAddress;
   4:  
   5: NetworkCredential NetworkCredential = new NetworkCredential(FromAddress.Address, "XXXXXXX");
   6: smtpclient.Credentials = NetworkCredential;
   7:  
   8: // Alternately you want you can try few different properties from MailAddress class.
   9:  
  10: Debug.WriteLine("DisplayName:  " +  FromAddress.DisplayName);
  11: Debug.WriteLine("Host:  " + FromAddress.Host);

This worked for my scenario. Happy coding.

Monday, July 15, 2013

Telugu Alphabets

Many of us tend to forget our own mother tongue with growing globalization or with the dominance of English being more used as communication medium. Here is what I thought should be useful for at least people like me to remember our own alphabets during the course of time.

I have captured from one of Facebook page where I thought sharing would help few of us Smile

Here are the Telugu alphabets

telugu alphabets

PS: I have copied this for the sake of my own repository. No offence or what so ever.

Download Microsoft SQL Server 2014 CTP

Microsoft has announced its most awaited version of SQL SERVER 2014 for Community Preview. The availability of the first public Community Technology Preview (CTP) of SQL Server 2014.

Here are key features of SQL Server 2014:

    • Mission critical performance across all database workloads with in-memory for online transaction processing (OLTP), data warehousing and business intelligence built-in as well as greater scale and availability
    • Hybrid cloud platform enabling organizations to more easily build, deploy and manage database solutions that span on-premises and cloud
    • Faster insights from any data with a complete BI solution using familiar tools like Excel

You can find more information from Microsoft blog here.

SQL SERVER 2012 Express version

Are you working on SQL Server 2005 or 2008 servers. Here is SQL Server 2012 Express version for download

Microsoft® SQL Server® 2012 Express is a powerful and reliable free data management system that delivers a rich and reliable data store for lightweight Web Sites and desktop applications.

Wednesday, June 05, 2013

How to Validate Date based on format “MM/dd/YYYY” in VB.NET

Here is the sample code snippet which I wrote to do date validation for a particular format and culture.

   1: Private Function validateDateFormat(ByVal strDate As String) As Boolean
   2:     Dim isValid As Boolean = True
   3:     Dim provider As CultureInfo = CultureInfo.GetCultureInfo("en-us")
   4:     Dim formats As String = "d" '"MM/dd/yyyy"
   5:     Dim dateValue As DateTime
   6:     Try
   7:         If DateTime.TryParseExact(strDate, formats, provider, DateTimeStyles.None, dateValue) Then
   8:             isValid = True
   9:         Else
  10:             isValid = False
  11:         End If
  12:     Catch ex As Exception
  13:  
  14:     End Try
  15:     Return isValid
  16: End Function


You can change the formats and CultureInfo to your own custom information. Here is my pervious blog which describes how formatting date time can be done using string object.