Archive for December 2013

How to detect Mobile Device Browsers?

We can easily detect the Mobile device browsers using the following C# code.
  1. public bool IsMobileDevice(string UserAgent)
  2. {
  3.     bool result = false;
  4.     Regex b = new Regex(@"(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino", RegexOptions.IgnoreCase | RegexOptions.Multiline);
  5.     Regex v = new Regex(@"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-", RegexOptions.IgnoreCase | RegexOptions.Multiline);
  6.     if ((b.IsMatch(userAgent) || v.IsMatch(userAgent.Substring(0, 4))))
  7.     {
  8.         result = true;
  9.     }
  10.     return result;
  11. }

  1. string userAgent = Context.Request.ServerVariables["HTTP_USER_AGENT"];
  2. var IsMobile = IsMobileDevice(userAgent);
Monday 30 December 2013
Posted by Jebastin
Tag :

How to hide the first option of a select using jQuery

When using "jquery.selectbox.js" plugin the "select & option" tags will be converted into "ul li" at run time. In this case it's hard to hide the first option using the normal select option script. The following solution rectifies this situation.

HTML:

  1. <div class="language">
  2. <select id="language" name="language" sb="76231018" style="display: none;">
  3. <option value="0">Select Language</option>
  4. <option value="http://www.example.com/en/" page="master">English</option>
  5. <option value="http://www.example.com/fr/" page="master">French</option>
  6. <option value="http://www.example.com/es/" page="master">Spanish</option>
  7. </select>
  8. <div id="sbHolder_76231018" class="sbHolder" tabindex="0">
  9.  <a id="sbToggle_76231018" href="#" class="sbToggle"></a>
  10.  <a id="sbSelector_76231018" href="#" class="sbSelector">Select Language</a>
  11.  <ul id="sbOptions_76231018" class="sbOptions" style="display: none;">
  12.    <li><a href="#0" rel="0" class="sbFocus">Select Language</a></li>
  13.    <li><a href="http://www.example.com/en/" rel="http://preview.smp.com/en/">English</a></li>
  14.    <li><a href="http://www.example.com/fr/" rel="http://preview.smp.com/fr/">French</a></li>
  15.    <li><a href="http://www.example.com/es/" rel="http://preview.smp.com/es/">Spanish</a></li>
  16.  </ul>
  17. </div>
  18. </div>

jQuery:

  1. <script type="text/javascript">
  2.     $(document).ready(function () {
  3.         $(".language .sbHolder").click(function () {
  4.             $(".language .sbHolder ul.sbOptions li:first").hide();
  5.         });
  6.     });
  7. </script>
Friday 20 December 2013
Posted by Jebastin
Tag : ,

Find the Distance between 2 Latitude Longitude Co-Ordinates using Haversine formula

The following function is used to find the distance between two Latitude & Longitude co-ordinates using Haversine formula.

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical triangles.

  1. public double HaversineDistance(LatLng pos1, LatLng pos2, DistanceUnit unit)
  2. {
  3.     double R = (unit == DistanceUnit.Miles) ? 3959 : 6371;
  4.     var la1 = pos1.Latitude;
  5.     var lo1 = pos1.Longitude;
  6.     var la2 = pos2.Latitude;
  7.     var lo2 = pos2.Longitude;
  8.     var lat1 = la1 * Math.PI / 180;
  9.     var lon1 = lo1 * Math.PI / 180;
  10.     var lat2 = la2 * Math.PI / 180;
  11.     var lon2 = lo2 * Math.PI / 180;
  12.     var dLat = lat2 - lat1;
  13.     var dLon = lon2 - lon1;
  14.     var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
  15.     var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
  16.     var d = R * c;
  17.     return d;
  18. }
  1. public class LatLng
  2. {
  3.     public double Latitude { get; set; }
  4.     public double Longitude { get; set; }
  5.     public LatLng()
  6.     {
  7.     }
  8.     public LatLng(double lat, double lng)
  9.     {
  10.         this.Latitude = lat;
  11.         this.Longitude = lng;
  12.     }
  13. }
Posted by Jebastin
Tag : ,

Microsoft SQL Server Function to Get Ordinal Suffix of a Number

This AddOrdinal function will be useful when we needed to display the date format as 1st July -3rd October. There is nothing in there about ordinals, but it can't be done using String.Format. However it's not really that hard to write a function to do it. The following Microsoft SQL Server Function is used to get the Ordinal Suffix of any number.
  1. CREATE FUNCTION [Internal].[GetNumberAsOrdinalString]
  2. (
  3.     @num int
  4. )
  5. RETURNS nvarchar(max)
  6. AS
  7. BEGIN
  8.     DECLARE @Suffix nvarchar(2);
  9.     DECLARE @Ones int; 
  10.     DECLARE @Tens int;
  11.     SET @Ones = @num % 10;
  12.     SET @Tens = FLOOR(@num / 10) % 10;
  13.     IF @Tens = 1
  14.     BEGIN
  15.         SET @Suffix = 'th';
  16.     END
  17.     ELSE
  18.     BEGIN
  19.     SET @Suffix =
  20.         CASE @Ones
  21.             WHEN 1 THEN 'st'
  22.             WHEN 2 THEN 'nd'
  23.             WHEN 3 THEN 'rd'
  24.             ELSE 'th'
  25.         END
  26.     END
  27.     RETURN CONVERT(nvarchar(max), @num) + @Suffix;
  28. END

 Related Function in other languages:

C# Code to Get Ordinal Suffix of a Number

PHP Code to Get Ordinal Suffix of a Number

Thursday 19 December 2013
Posted by Jebastin
Tag :

PHP Code to Get Ordinal Suffix of a Number

It's a user-defined function which is a lot simpler than you think. Though there might be a .NET function already in existence for this, the following function (written in PHP) does the job. It shouldn't be too hard to port it over. This ordinal function will be useful when we needed to display the date format as 1st December 2013.
  1. function ordinal($num) {
  2.     $ones = $num % 10;
  3.     $tens = floor($num / 10) % 10;
  4.     if ($tens == 1) {
  5.         $suff = "th";
  6.     } else {
  7.         switch ($ones) {
  8.             case 1 : $suff = "st"; break;
  9.             case 2 : $suff = "nd"; break;
  10.             case 3 : $suff = "rd"; break;
  11.             default : $suff = "th";
  12.         }
  13.     }
  14.     return $num . $suff;
  15. }

 Related Function in other languages:

C# Code to Get Ordinal Suffix of a Number

Microsoft SQL Server Function to Get Ordinal Suffix of a Number

Posted by Jebastin
Tag :

C# Code to Get the Latitude and Longitude Co-Ordinates of a Place using Address or Zip-code

The following C# Code is used to get the Latitude and Longitude Co-Ordinates of a particular place anywhere in the World using the Address or Zip-code. To get the Latitude and Longitude Co-Ordinates using Address, call the function like this, getLatLong("Briarwood, NY 11435-2694",""). To get the Latitude and Longitude Co-Ordinates using the Zip-code, call the function like this, getLatLong("","11435").
  1. public string getLatLong(string Address, string Zip)
  2. {
  3.     string latlong = "", address = "";
  4.     if (Address!=string.Empty)
  5.     {
  6.         address = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + Address + "&sensor=false";
  7.     }
  8.     else
  9.     {
  10.         address = "http://maps.googleapis.com/maps/api/geocode/xml?components=postal_code:" + Zip.Trim() + "&sensor=false";
  11.     }
  12.     var result = new System.Net.WebClient().DownloadString(address);
  13.     XmlDocument doc = new XmlDocument();
  14.     doc.LoadXml(result);
  15.     XmlNodeList parentNode = doc.GetElementsByTagName("location");
  16.     var lat = "";
  17.     var lng = "";
  18.     foreach (XmlNode childrenNode in parentNode)
  19.     {
  20.         lat = childrenNode.SelectSingleNode("lat").InnerText;
  21.         lng = childrenNode.SelectSingleNode("lng").InnerText;
  22.     }
  23.     latlong = Convert.ToString(lat) + "," + Convert.ToString(lng);
  24.     return latlong;
  25. }
Posted by Jebastin
Tag : ,

C# Code to Get Ordinal Suffix of a Number

There is no inbuilt capability in the .NET Base Class Library to get the Ordinals. This AddOrdinal function will be useful when we needed to display the date format as 1st July -3rd October. There is nothing in there about ordinals, but it can't be done using String.Format. However it's not really that hard to write a function to do it. The following C# code is used to get the Ordinal Suffix of any number.
  1. public static string AddOrdinal(int num)
  2. {
  3.     if (num <= 0) return num.ToString();
  4.     switch (num % 100)
  5.     {
  6.         case 11:
  7.         case 12:
  8.         case 13:
  9.             return num + "th";
  10.     }
  11.     switch (num % 10)
  12.     {
  13.         case 1:
  14.             return num + "st";
  15.         case 2:
  16.             return num + "nd";
  17.         case 3:
  18.             return num + "rd";
  19.         default:
  20.             return num + "th";
  21.     }
  22. }

Another way:

  1. public static string[] SuffixLookup = { "th","st","nd","rd","th","th","th","th","th","th" };
  2.  
  3. public static string AppendOrdinalSuffix(int number)
  4. {
  5. if (number % 100 >= 11 && number % 100 <= 13)
  6. {
  7. return number + "th";
  8. }
  9. return number + SuffixLookup[number% 10];

And the more simplest way:

  1. private static string GetOrdinalSuffix(int num)
  2. {
  3.     if (num.ToString().EndsWith("11")) return "th";
  4.     if (num.ToString().EndsWith("12")) return "th";
  5.     if (num.ToString().EndsWith("13")) return "th";
  6.     if (num.ToString().EndsWith("1")) return "st";
  7.     if (num.ToString().EndsWith("2")) return "nd";
  8.     if (num.ToString().EndsWith("3")) return "rd";
  9.     return "th";

 Related Function in other languages:

PHP Code to Get Ordinal Suffix of a Number

Microsoft SQL Server Function to Get Ordinal Suffix of a Number

Posted by Jebastin
Tag : ,

How to prevent resizing of TextArea?

We need to disable the re-sizable property of a TextArea. Normally, we can resize a TextArea by clicking on the bottom right corner of the TextArea and dragging the mouse. The following CSS is used to disable this behaviour.

Use the following CSS rule to disable this behavior for all TextArea elements:
  1. textarea {
  2.     resize: none;
  3. }
If you want to disable it for some (but not all) TextArea elements, you have a couple of options (thanks to this page).

To disable a specific TextArea with the name attribute set to foo (i.e., <TextArea name="foo"></TextArea>):
  1. textarea[name=foo] {
  2.     resize: none;
  3. }
Or, using an ID (i.e., <TextArea id="foo"></TextArea>):
  1. #foo {
  2.     resize: none;
  3. }
Sunday 15 December 2013
Posted by Jebastin
Tag : ,

How to get current HTML Page Title/URL with jQuery/Javascript?

Get current HTML page Title and URL with jQuery and Javascript.

Current Page Title:

jQuery:

  1. var title = $(document).find("title").text();
  2. (or)
  3. var title = $('title').text(); 
  4. (or)
  5. var title = $(document).attr('title');

Javascript:

  1. var title = document.getElementsByTagName("title")[0].innerHTML;

Current Page URL:

jQuery:

  1. var url = $(location).attr('href');
  2. (or)
  3. var url = $(location).attr('pathname');

Javascript:

  1. var url = document.URL
  2. (or)
  3. var url = window.location.href
  4. (or)
  5. var url = window.location.pathname;
Posted by Jebastin

Web Service to filter the Umbraco Nodes

Web Service to filter the Umbraco Nodes

The following WebMethod is used to filter the Umbraco child nodes of a particular parent node using the given parent id by the parameters Keyword, Job Type, Position, Location, Category and Division.

Web Method:

  1. public List<JobDetails> FilterJobs(int ParentId, string Keyword, string JobType, string Position, string Location, string Category, string Division)
  2. {
  3. string strJobId = "", strJobDescription = "", strJobRequirements = "", strJobType = "";
  4. string strJobPosition = "", strJobLocation = "", strJobCategory = "", strJobDivision = "";
  5. dynamic JobsNode = new DynamicNode().NodeById(ParentId);
  6. List<DynamicNode> JobsList = JobsNode.Children.Items;
  7. List<JobDetails> FilteredJobsList = new List<JobDetails>();
  8. JobsList = JobsList.Where(x => x.GetProperty("descriptionOfDuties").Value.Contains(Keyword) ||
  9.         x.GetProperty("requirementsExperience").Value.Contains(Keyword) ||
  10.         x.GetProperty("jobType").Value.Contains(Keyword) ||
  11.         x.GetProperty("position").Value.Contains(Keyword) ||
  12.         x.GetProperty("location").Value.Contains(Keyword) ||
  13.         x.GetProperty("category").Value.Contains(Keyword) ||
  14.         x.GetProperty("division").Value.Contains(Keyword) ||
  15.         Keyword == "").ToList();
  16. JobsList = JobsList.Where(x => (x.GetProperty("jobType").Value.Equals(JobType) || JobType == "") &&
  17.         (x.GetProperty("position").Value.Equals(Position) || Position == "") &&
  18.         (Location.Split(',').Contains(x.GetProperty("location").Value.Replace(",", "")) || Location == "") &&
  19.         (Category.Split(',').Contains(x.GetProperty("category").Value) || Category == "") &&
  20.         (Division.Split(',').Contains(x.GetProperty("division").Value) || Division == "")).ToList();
  21. foreach (var job in JobsList)
  22. {
  23.     strJobId = Convert.ToString(job.Id);
  24.     strJobDescription = job.GetProperty("descriptionOfDuties").Value;
  25.     strJobRequirements = job.GetProperty("requirementsExperience").Value;
  26.     strJobType = job.GetProperty("jobType").Value;
  27.     strJobPosition = job.GetProperty("position").Value;
  28.     strJobLocation = job.GetProperty("location").Value;
  29.     strJobCategory = job.GetProperty("category").Value;
  30.     strJobDivision = job.GetProperty("division").Value;
  31.     FilteredJobsList.Add(new JobDetails
  32.     {
  33.         JobId = strJobId.Trim(),
  34.         JobDescription = strJobDescription.Trim(),
  35.         JobRequirements = strJobRequirements.Trim(),
  36.         JobType = strJobType.Trim(),
  37.         JobPosition = strJobPosition.Trim(),
  38.         JobLocation = strJobLocation.Trim(),
  39.         JobCategory = strJobCategory.Trim(),
  40.         JobDivision = strJobDivision.Trim()
  41.     });
  42. }
  43. return FilteredJobsList;
  44. }

Properties:

  1. public class JobDetails
  2. {
  3.     public string JobId { get; set; }
  4.     public string JobDescription { get; set; }
  5.     public string JobRequirements { get; set; }
  6.     public string JobType { get; set; }
  7.     public string JobPosition { get; set; }
  8.     public string JobLocation { get; set; }
  9.     public string JobCategory { get; set; }
  10.     public string JobDivision { get; set; }
  11. }
Saturday 14 December 2013
Posted by Jebastin

How to call a WebMethod of a Web Service using jQuery Ajax JSON?

How to call a WebMethod of a Web Service using jQuery Ajax JSON

The following jQuery is used to call a WebMethod of a Web Service using jQuery Ajax JSON.

jQuery:

  1. $(document).ready(function () {
  2. var Name = $("#name").val();
  3. var Email = $("#email").val();
  4. var Message = $("#msg").val();
  5. $.ajax({
  6.     type: "POST",
  7.     data: "{'Name':'" + Name + "','Email':'" + Email + "','Message':'" + Message + "'}",
  8.     url: "/WebServices/WS.asmx/Contact",
  9.     contentType: "application/json; charset=utf-8",
  10.     dataType: "json",
  11.     success: function (response) {
  12.         if (response.d == true) {
  13.             alert("Thank you for contacting JJ Technology Solutions.");
  14.         }
  15.         else {
  16.             alert("Error sending email. Please try again later.");
  17.         }
  18.     }
  19. });
  20. });
Posted by Jebastin

How to find the value of a HTML tag attribute using jQuery?

Note: 

When using "jquery.selectbox.js" plugin the "select & option" tags will be converted into "ul li" at run time. The problem is we can not get the selected value using the normal jQuery or Javascript when we use this plugin. The following solution rectifies this situation. 

Here we are going to find the 'rel' attribute value of an anchor tag which is the selected option.

HTML:

  1. <fieldset class="sapDD medium">
  2. <span class="required">*</span>
  3. <select id="Division" name="Division" sb="37042751" style="display: none;">
  4.     <option value="">Select a Division</option>
  5.     <option value="example1@gmail.com" selected="selected">example1</option>
  6.     <option value="example2@gmail.com">example2</option>
  7.     <option value="example3@gmail.com">example3</option>
  8.     <option value="example4@gmail.com">example4</option>
  9. </select>
  10. <div id="sbHolder_37042751" class="sbHolder" tabindex="0">
  11.     <a id="sbToggle_37042751" href="#" class="sbToggle"></a>
  12.     <a id="sbSelector_37042751" href="#" class="sbSelector">example1</a>
  13.     <ul id="sbOptions_37042751" class="sbOptions" style="top: 16px; max-height: 583px; display: none;">
  14.         <li><a href="#" rel="" class="">Select a Division</a></li>
  15.         <li><a href="#example1@gmail.com" rel="example1@gmail.com" class="">example1</a></li>
  16.         <li><a href="#example2@gmail.com" rel="example2@gmail.com">example2</a></li>
  17.         <li><a href="#example3@gmail.com" rel="example3@gmail.com">example3</a></li>
  18.         <li><a href="#example4@gmail.com" rel="example4@gmail.com">example4</a></li>
  19.     </ul>
  20. </div>
  21. </fieldset>

jQuery:

  1. $(document).ready(function(){
  2. var Division = $("#Division").next(".sbHolder").find("a.sbSelector").text(); ;
  3. var DivisionEmail = $("#Division").next(".sbHolder").find("ul.sbOptions").find("a:contains('" + Division + "')").attr("rel");
  4. alert(DivisionEmail);
  5. });
Posted by Jebastin
Tag : ,

How to insert values in SQL Server database table using Umbraco?

Required Namespaces:

  1. using umbraco;
  2. using umbraco.BusinessLogic;
  3. using umbraco.DataLayer;

C# Code:

  1. public bool InsertData(string FirstName, string LastName, string Email, string Phone)
  2. {
  3. bool IsSuccessful = false;
  4. try
  5. {
  6. string InsertQuery = "INSERT INTO tblPerson(FirstName, LastName, Email, Phone, CreatedDate) values ";
  7. InsertQuery = InsertQuery + "(@FirstName, @LastName, @Email, @Phone, @CreatedDate)";
  8. Application.SqlHelper.ExecuteNonQuery(InsertQuery,
  9. Application.SqlHelper.CreateParameter("@FirstName", FirstName),
  10. Application.SqlHelper.CreateParameter("@LastName", LastName),
  11. Application.SqlHelper.CreateParameter("@Email", Email),
  12. Application.SqlHelper.CreateParameter("@Phone", Phone),
  13. Application.SqlHelper.CreateParameter("@CreatedDate", DateTime.Now));
  14. IsSuccessful = true;
  15. }
  16. catch
  17. {
  18. IsSuccessful = false;
  19. }
  20. return IsSuccessful;
  21. }
Posted by Jebastin

How to send email using SMTP in ASP.Net / C#?

C#:

  1. public bool Send_Email(string Subject, string Body, string ToEmail, string AttachmentUrl)
  2. {
  3. bool Sent = false;
  4. try
  5. {
  6. if (!string.IsNullOrEmpty(ToEmail))
  7. {
  8. string FromEmail = "", Username = "", Password = "", Host = "", Port = "";
  9. FromEmail = Convert.ToString(ConfigurationManager.AppSettings["FromEmail"]);
  10. Username = Convert.ToString(ConfigurationManager.AppSettings["Username"]);
  11. Password = Convert.ToString(ConfigurationManager.AppSettings["Password"]);
  12. Host = Convert.ToString(ConfigurationManager.AppSettings["Host"]);
  13. Port = Convert.ToString(ConfigurationManager.AppSettings["Port"]);
  14. bool UseSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSsl"]);
  15. System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
  16. System.Net.NetworkCredential cred = new System.Net.NetworkCredential(Username, Password);
  17. if (ToEmail.Contains(','))
  18. {
  19. string[] ToEmailArray = ToEmail.Split(',');
  20. foreach (string si in ToEmailArray)
  21. {
  22.     mail.To.Add(si);
  23. }
  24. }
  25. else
  26. {
  27. mail.To.Add(ToEmail);
  28. }
  29. mail.Subject = Subject;
  30. mail.From = new System.Net.Mail.MailAddress(FromEmail, Convert.ToString(ConfigurationManager.AppSettings["FromName"]));
  31. mail.IsBodyHtml = true;
  32. mail.Body = Body;
  33. if (!string.IsNullOrEmpty(AttachmentUrl))
  34. {
  35. System.Net.Mail.Attachment Attachment;
  36. if (AttachmentUrl.Contains(','))
  37. {
  38.     string[] AttachmentUrlArray = ToEmail.Split(',');
  39.     foreach (string url in AttachmentUrlArray)
  40.     {
  41.         string strUrl = Uri.EscapeUriString(url);
  42.         if (File.Exists(strUrl))
  43.         {
  44.             Attachment = new System.Net.Mail.Attachment(strUrl);
  45.             mail.Attachments.Add(Attachment);
  46.         }
  47.     }
  48. }
  49. else
  50. {
  51.     string strUrl = Uri.EscapeUriString(AttachmentUrl);
  52.     if (File.Exists(strUrl))
  53.     {
  54.         Attachment = new System.Net.Mail.Attachment(strUrl);
  55.         mail.Attachments.Add(Attachment);
  56.     }
  57. }
  58. }
  59. System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
  60. smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
  61. smtp.UseDefaultCredentials = false;
  62. smtp.EnableSsl = UseSsl;
  63. smtp.Credentials = cred;
  64. smtp.Host = Host;
  65. smtp.Port = Convert.ToInt32(Port);
  66. smtp.Send(mail);
  67. Sent = true;
  68. }
  69. }
  70. catch
  71. {
  72. Sent = false;
  73. }
  74. return Sent;
  75. }

Configuration in appSettings.config:

  1.  <!-- Email Data Configuration Start -->
  2.   <add key="FromName" value="Company Name or Any Text"/>
  3.   <add key="FromEmail" value="example@gmail.com"/>
  4.   <add key="Username" value="example@gmail.com"/>
  5.   <add key="Password" value="password"/>
  6.   <add key="Host" value="smtp.gmail.com"/>
  7.   <add key="Port" value="587"/>
  8.   <add key="UseSsl" value="true"/>
  9.   <add key="ToEmail" value="example@gmail.com"/>
  10.   <!-- Email Data Configuration End -->
Posted by Jebastin

How to enable the remote testing of webservice methods in live environment?

Scenario: 

The test form is only available for requests from the local machine.

Solution: 

For enabling remote web service test page, just add HttpPost/HttpGet protocol in the webServices section of your web.config. By default, this option is disabled to increase the security in live environment, but you can enable it in web.config as follows for debugging the deployed web services.
  1. <webServices>
  2.    <protocols>
  3.       <add name="HttpGet"/>
  4.       <add name="HttpPost"/>     
  5.    </protocols>
  6. </webServices>
Please rollback these settings after testing/debugging your deployed web services on live server.
Posted by Jebastin

How to resolve “HTTP Error 500.19 - Internal Server Error” on IIS

Error:

HTTP Error 500.19-Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Solution:

Step 1: 

Start Visual studio command prompt as an administrator as shown in the picture below:


Step 2: 

In the visual studio command prompt type the command aspnet_regiis –i and then press Enter as shown in picture below:


Step 3: 

Installation process will take some time and once finished it will display finished installing message. After installation again refresh site in IIS and browse it again.
Friday 13 December 2013
Posted by Jebastin

How to find the Document Type Alias of the First Child Node using Razor?

To find the Document Type Alias of the First Child Node using Razor.
  1. @Model.Children.First().NodeTypeAlias
Thursday 12 December 2013
Posted by Jebastin

Link To This Post/Page

Spread The Word

Add this button to your blog:
JJ Technology Solutions

Blog Archive

Trackers

eXTReMe Tracker
facebook

- Copyright © JJ Technology Solutions - Powered by Source Code Solutions -