Quick Tip

Send Email from Asp.Net Application using Google Account and SMTP

In order to send mail from the application we can use SMTP server from Google (which off course has certain limitations). We can use a Google mail account and send the mail using SMTP server from Google. This works very well for Asp.net applications which need to use a simple form such as “Contact Us”. An example of this is explained below. We will use AJAX to send the request to an ASP.Net web service which sends the mail from the server side. Create a web service as following using System; using System.Configuration; using System.Net.Mail; using System.Web.Services; namespace GoDaddy.Email { /// <summary> /// Summary description for Mail /// </summary> [WebService(Namespace = “http://tempuri.org/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class Mail : System.Web.Services.WebService { [WebMethod] public string SendEmail(string to, string subject, string body)[…]

Quick Tip

Convert C# Object to JSON and create object from JSON string

Json.Net is the preferred way to go about it because of performance gain it gets compared to JavascriptSerializer. Download and install Newtonsoft.Json using Nuget Now in order to create Json for an object simply use SerializeObject method as following Product product = new Product(); product.Name = “Apple”; product.Expiry = new DateTime(2008, 12, 28); product.Sizes = new string[] { “Small” }; string json = JsonConvert.SerializeObject(product); // { // “Name”: “Apple”, // “Expiry”: “2008-12-28T00:00:00”, // “Sizes”: [ // “Small” // ] // } In order to convert Json to the object use DeserializeObject method as following string json = @”{ ‘Name’: ‘Bad Boys’, ‘ReleaseDate’: ‘1995-4-7T00:00:00’, ‘Genres’: [ ‘Action’, ‘Comedy’ ] }”; Movie m = JsonConvert.DeserializeObject<Movie>(json); string name = m.Name; // Bad Boys  

Commenting Etiquettes While You are on Web !!

Now a days commenting on posts or blogs is not just what people do out of their interests only but also it is really important to be an active commenter on the social media to mark your presence known and maintain overall awareness about the updates. It helps in building links with others, building a community and sharing your views. Comments also reveal the engagement of your content. While sharing your views anywhere be it on a blog or some social networking post, you have to make sure that your comments are expressed in a good way. There are certain things to be taken care of before you comment. Here they are: • Make Valuable Comments: Make sure to never comment without proper knowledge about the subject and reading of the content. Comments should not be done just to make noise but to add on to the information. You can add a story related to a post[…]

Quick Tip

Tip of the day: Blank href in html A link

When you are using <a> link and want to bind it with onclick event in stead of href location, it can be set to # as following <a href=”#” onclick=”javascript:callMethod();”>Link</a> As you know setting href to “#some_id” is an approach used to link content inside the page so if you are using above approach, it will make the page jump to top which is not an elegant solution. There is an alternate way which is much better as it does not make page jump. <a href=”javascript:void(0)” onclick=”javascrit:callMethod();”>Link</a> Simple and elegant..