Wednesday, July 06, 2011

How to find the WeekEnd days in C#

This code snippet will used to find out the WeekEnd days in C#.Once you find out then you can write your own business requirement logic to be build.
  public bool isWeekEnd(DateTime dt)
    {
        if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
        { return true; }
        else
        { return false; }

    }


Tuesday, July 05, 2011

Enumerating different items from Arrays

This morning I started to working on some thing to compare the two array list or array values and identifying the similarities and differential items.
The below code is equivalent to looping the both arrays and identifying the common and different items in two array values.


In C#.NET 3.5 We have Intersect and Except extension method to get solution for these kind scenarios.
List List1 = new List();
List1.Add("Murugesan");
List1.Add("Geetha");
List1.Add("GuruSelvam");


List List2 = new List();
List2.Add("Murugesan");
List2.Add("Geetha");


List exce = List1.Except(List2).ToList();
foreach (string n in exce)
{
Response.Write(n.ToString());
}
//It will returns the GuruSelvam

Monday, July 04, 2011

export sharepoint site

Today i learned some more deeply about site collection data backup with all attributes of sites such as versions of contents,security permission level.file compression during export and import of the site using sharepoint 2010 powershell cmdlets.
I am on preparing for the exam 70-667 sharepoint 2010 configure.i always use the beckybertram blog for microsoft exam preparation.


Friday, July 01, 2011

C# SMTP email sending code

When I tested this code in webapplication its works fine.But my webmail server is HTTPS based and I wanted to integrate this into my SharePoint webpart.

In this case,set EnableSsl true on your smtp object and specify the port number if you are not using the SMTP's default port 25.

Still you got an error use the below code to off the Certificate Validation while relying on HTTP.
If you are an developer and testing it on the PC where you installed "fiddler".Just make sure its Off.
Use the below line just before to Send method.
 System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; 
try
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtp = new SmtpClient("webmail smtp");

            mail.From = new MailAddress("user@webmail.com");
            mail.To.Add("murugesa.pandian@webmail.com");
           
            mail.CC.Add("CC");

            mail.Subject = "Subject";
            mail.Body = "Email contents";


            smtp.Credentials = new System.Net.NetworkCredential("userid", "pwd");
            smtp.EnableSsl = true;

            smtp.Send(mail);
            Response.Write("Sent !");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }