Posts

Showing posts from June, 2016

Donate

Show Or Get IP Address in ASP.NET MVC

Here's a simple tutorial on how to get a user's IP address using ASP.NET MVC and jQuery. The fetching of record is triggered when the textbox receives focus. HTML Code 1 <input id= "txtID" type= "text" /> JavaScript Code 1 2 3 4 5 6 7 8 $(document).ready( function () { $( '#txtID' ).focus( function () { $.getJSON( '@Url.Action("GetIPAddress","getipaddress")' , function (result) { $( "#txtID" ).val(result); }); }); }); C# Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public JsonResult GetIPAddress() { System.Web.HttpContext context = System.Web.HttpContext.Current; string ipAddress = context.Request.ServerVariables[ "HTTP_X_FORWARDED_FOR" ]; string output = string .Empty; if (! string .IsNullOrEmpty(ipAddress)) { string [] addresses = ipAddress.Split( ',' )...

Operating System Error 5(Access is denied.) "Cannot open backup device" in SQL Server

Image
Here's how I manage to solve the issue Cannot open backup device with status Operating system error 5(Access is denied.) Steps 1. Right Click the Folder which is the backup destination 2. Click Properties -> Security Tab -> Click Advanced Button 3. On Permissions Tab -> choose Add -> Select Principal 4. In the "Enter the object name to select", type " NT Service\MSSQLSERVER ". -> OK     Note: NT Service\MSSQLSERVER is the Log On As value of     MSSQLSERVER service under Services. See screenshot below 5. In Multiple Names Found choose MSSQLSERVER. 6. Click OK 7. In Basic permissions panel, Choose Full Control 8. Click Apply -> OK -> OK to close Folder Properties dialog box SQL Server Service

How To Unpivot In SQL Server With Example

Image
Given the following records below, you may want to show them in a vertical manner instead of horizontal view of columns. To achieve the desired result, you use UNPIVOT clause in your query. 1 2 3 4 5 6 7 8 Use testdatabase Go SELECT [Subject], Grade FROM StudentReportCard UNPIVOT (Grade FOR [Subject] IN (English, Math, Literature, Biology)) AS U_SubjectGrade WHERE StudentId = 1 Screenshot

Webbrowser GetAttribute("class") Method Not Working

When working with Webbrowser's GetAttribute() method, you often encountered an issue wherein GetAttribute("class") does not work as expected. 1 2 3 if (Element.GetAttribute( "class" ).Contains( "_textFontColor" )) { //other codes here } After investigating from MSDN docs, I found out a comment below the documentation which states that you have to use className instead of class. Well, that did the trick. :-) 1 2 3 4 5 6 7 8 9 10 11 12 13 HtmlElementCollection elements = WebBrowser1.Document.GetElementsByTagName( "A" ); foreach (HtmlElement Element in elements) { if (Element.GetAttribute( "className" ).Contains( "_textFontColor" )) { //other codes here } } HtmlElementCollection elements = WebBrowser1.Document.GetElementsByTagName( "a" ); foreach (HtmlElement Element in elements) { if (Element.GetAttribute( "className" ).Contains( "_textFontColor" ))...

Bootstrap DatePicker Control In ASP.NET Web Forms

Image
Here's how to integrate Bootstrap DatePicker widget in you ASP.NET Webforms Project. First, you need to add reference to the following JS and CSS files: bootstrap.min.css , bootstrap-datepicker3.standalone.css , jquery-1.11.1.min.js , bootstrap.min.js , bootstrap-datepicker.min.js . 1 2 3 4 5 <link rel= "stylesheet" href= "Content/bootstrap.min.css" /> <link rel= "stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/css/bootstrap-datepicker3.standalone.css" /> <script type= "text/javascript" src= "Scripts/jquery-1.11.1.min.js" ></script> <script type= "text/javascript" src= "Scripts/bootstrap.min.js" ></script> <script type= "text/javascript" src= "https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.1/js/bootstrap-datepicker.min.js" ></script> Create a simple registration form with B...

WPF DataGrid Excel Comment Indicator

Image
Here's how to add a comment indicator to a DataGridCell similar to an Excel functionality using MultiValueConverter. See codefiles and screenshot below. XAML 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 <Window x:Class= "WPFExcelCommentIndicator.DataGridCellCommentIndicator" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src= "clr-namespace:WPFExcelCommentIndicator" Title= "DataGridCellCommentIndicator" Height= "350" Width= "500" WindowStartupLocation= "CenterScreen" > <Window.Resources> <src:DataGridCellComment x:Key= "DataGridCellComment" /> <src:StudentList x:Key= "StudentListData" /> </W...

How To Convert DataTable To List Using LINQ And C#

Hello, The code below converts a DataTable object to generic List object using LINQ and C#. It assumes that the DataTable columns match with class properties. C# Code 1 2 3 4 5 6 7 8 var personEnumerable = table.AsEnumerable(); List<Person> ListPosition = new List<Person>(); ListPosition = ( from item in personEnumerable select new Person { ID = item.Field< int >( "ID" ).ToString(), Salary = item.Field< double >( "Salary" ).ToString() }).ToList(); Class 1 2 3 4 5 public class Person { public string ID { get ; set ; } public string Salary { get ; set ; } }

Donate