Posts

Detect Browser In Code Behind ASP.NET

Image
Certain javascript will work on certain browser only. So inorder to avoid your client from using the application which is bot supported by your application, you can filter the browser type from code behind of your web application.   Let see the example The ASPX page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>     <form id="form1" runat="server">     <div>         </div>     </form> </body> </html> The Code Behind  protected void Page_Load(object sender, EventArgs e)         {             System.Web.HttpBrowserCapabilities browser = Request.Browser;             string s = "Browser Capabilities &lt;br/&gt;"                 + "Type = " + browser.Type

How to alter DataTable to add new Column -C#, asp.net

Image
In this tutorial i will show how to manipulate the DataTable to append with new column. In this example i will retrieve data from database using SqlDataAdapter, you can refer this tutorial to know how to using SqlDataAdapter. After fill DataTable with data, the program will append the column of the DataTable. Lets check on the example below. The Database Table "Users" SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Users](     [Userid] [varchar](50) NOT NULL,     [UserEmail] [varchar](50) NOT NULL,     [DateTimeCreated] [datetime] NOT NULL,     [CreatedBy] [varchar](50) NOT NULL,     [DateTimeModified] [datetime] NULL,     [ModifiedBy] [varchar](50) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO INSERT [dbo].[Users] ([Userid], [UserEmail], [DateTimeCreated], [CreatedBy], [DateTimeModified], [ModifiedBy]) VALUES (N'developers', N'developersnote@gmail.com', CAST(0x0000A284014950B0 AS DateTime), N'SYS', NULL, N

Get Method Names using Reflection [C#]

Image
If you want to get method names of a given type in C#, you can use method Type.GetMethods. This method returns array of MethodInfo objects. MethodInfo contains many informations about the method and of course a method name (MethodInfo.Name). To filter returned methods (for example if you want to get only public static methods) use BindingFlags parameter when calling GetMethods method. Required are at least two flags, one from Public/NonPublic and one of Instance/Static flags. Of course you can use all four flags and also DeclaredOnly and FlattenHierarchy. BindingFlags enumeration and MethodInfo class are declared in System.Reflection namespace. The example will show method name and return type of the method of developersnote class The developersnote Class     public class developersnoteClass     {         public developersnoteClass()         {         }         public void ConvertDateTime()         {         }         public static void ConvertInteger()         {         }         publ

Read data from DataTable - C#

This is the example of reading data from datatable : The code explaination : The code will retrieve data from database and store into databable. Andthen , the code will continue by looping each row in a datatable and try to read every column on the row. The Code     using System;     using System.Data;     using System.Data.SqlClient;     class PopDataset     {        static void Main()        {           string connString = "<connection string>";           string sql = "select * from employee";           SqlConnection conn = new SqlConnection(connString);           try           {          DataTable dt = new DataTable();              conn.Open();              SqlDataAdapter da = new SqlDataAdapter(sql, conn);                da.Fill(dt);          conn.Close();                          foreach (DataRow row in dt.Rows)              {         //read each column in row                 foreach (DataColumn col in dt.Columns)         {                    Console.Writ

Java - Get Visitor/Client ip address : JSP : Servlet

The previous post show how to get Visitor or client ip address in C# / ASP.NET . This post will show how to get ip address of client / visitor from jsp / servlet application. In order to make this method work, you need to test this method on the server and you are accessing the server from your computer. Otherwise you will get your local ipaddress or ::1 value. The getClientIpAddr Method      public static String getClientIpAddr(HttpServletRequest request) {          String ip = request.getHeader("X-FORWARDED-FOR");          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {              ip = request.getHeader("Proxy-Client-IP");          }          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {              ip = request.getHeader("WL-Proxy-Client-IP");          }          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {              ip = request.getHeader(&

C# - Get Visitor/Client ip address : ASP.NET

If you want to get the ip address of users from asp.net web application when user access the web page, you can use this method to return the Client / visitor ip address. Method GetVisitorIPAddress - .Net 4 and above         /// <summary>         /// method to get Client ip address         /// </summary>         /// <param name="GetLan"> set to true if want to get local(LAN) Connected ip address</param>         /// <returns></returns>         public static string GetVisitorIPAddress(bool GetLan = false)         {             string visitorIPAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];             if (String.IsNullOrEmpty(visitorIPAddress))                 visitorIPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];             if (string.IsNullOrEmpty(visitorIPAddress))                 visitorIPAddress = HttpContext.Current.Request.UserHostAddress;             if (string

Netbean : java.lang.OutOfMemoryError: Java heap space - Solutions

Image
In java application development, sometimes your application will throw an exception run: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at com.classpackage.MainConsole.main(MainConsole.java:24) Java Result: 1 This is because your program consuming a lot of memory. One of the solutions is to increase the Xms and Xmx argument on the project. Lets see the example : The Main Class import java.util.ArrayList; import java.util.List; public class MainConsole {     public static void main(String[] args){         List<PhoneContacts> phoneContacts = new ArrayList<PhoneContacts>();         // You can use diamond inference in JDK 7 like example below         //List<PhoneContacts> phoneContacts = new ArrayList<>();                 for(int index = 0;index< 10000000;index++ ){             PhoneContacts p = new PhoneContacts();             p.setFirstName("developersnote" + Integer.toString(index));             p.setLastName(&qu