Posts

Showing posts from November, 2013

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

SCRIPT5007: Unable to get value of the property '0': object is null or undefined - jquery.jqGrid.js

Image
If you try to create data grid using mvc jqGrid and somehow the error above occur while debugging script using IE Debugger. Please follow this step to fix it.. The error because of in your mvc jqGrid coding, you not specify the json reader. Just add this line of code in your View and also in your mvc jqGrid . The Solution @{                 MvcJqGrid.DataReaders.JsonReader jsonReader = new MvcJqGrid.DataReaders.JsonReader();                 jsonReader.RepeatItems = false;                 jsonReader.Id = "dataJson";             } @(Html.Grid("GridDataBasic")                 .SetCaption("List Of User")                 .AddColumn(new Column("AdminID"))                 .AddColumn(new Column("Email"))                 .AddColumn(new Column("Tel"))                 .AddColumn(new Column("Role"))                 .AddColumn(new Column("Active"))                 .SetUrl("/Home/GridDataBasic")             

Simple Image Galery in PHP - Example

Image
This post is a different from others post. because in this example i will use PHP language to create very simple Image Galery. The code will get list from image directory, and the build a image tag element in html to show the image. Very simple. Lets see the example. The  Project list Folder and file The PHP File  <html>     <body>                <h1>Image Gallery</h1>                <div style="width:640px;">             <?php             //change directory to image stored location             //if image is at another server try to do like this             //$dir = 'http://<server ip address>/<location at server>'             //make sure image is accessible             $dir    = 'Images';             $files1 = scandir($dir);                                   foreach ($files1 as $value) {                 if(strtoupper(explode('.', $value)[1]) == "JPG"){//make sure image is JPG or just remove this f

How to use PathGradientBrush WrapMode Property

Image
Here The code To Create Page like picture above. The code behind protected void Button1_Click(object sender, EventArgs e)         {             Bitmap bmp = new Bitmap(600, 300);             Graphics g = Graphics.FromImage(bmp);             g.Clear(Color.White);             GraphicsPath gPath = new GraphicsPath();             Rectangle rect = new Rectangle(0, 0, 100, 100);             gPath.AddRectangle(rect);             PathGradientBrush pathGradientBrush = new PathGradientBrush(gPath);             pathGradientBrush.CenterColor = Color.Crimson;             Color[] colors = { Color.Snow, Color.IndianRed };             pathGradientBrush.SurroundColors = colors;             pathGradientBrush.WrapMode = WrapMode.Tile;             Rectangle rect2 = new Rectangle(0, 0, 300, 300);             g.FillRectangle(pathGradientBrush, rect2);             pathGradientBrush.WrapMode = WrapMode.TileFlipXY;             Rectangle rect3 = new Rectangle(300, 0, 300, 300);             g.FillRectangl

Javascript - Inline Code VS External Files

Inline Code <html> <head> <script type="text/javascript"> function a() { alert('hello world'); } </script> </head> <body> : : </body> </html> External Files <html> <head> <script type="text/javascript" src="/scriptone.js"> </script> </head> <body> : : </body> </html> scriptone.js function a() { alert('hello world'); } As you can see from the above example,  what is the advantage to put all script in one file and just call it from html( External Code ) instead of just write it in html( inline code ).? The answer is here :  By using external code, the javascript code is much more maintainability :- javascript Code that is sprinkled throughout various HTML pages turns code maintenance into a problem. It is much easier to have a directory for all javascript files so that developers can edit JavaScript code independent of the markup in which it is u

Step by step how to create MVCJQGrid ASP.NET MVC4

Image
First step is to install MVCJQGrid in your project application(MVC). In This tutorial i will show you how to install MVCJQGrid using NuGet in Microsoft Visual Studio 2010. Install MVCJQGrid 1. In VS2010 open NuGet Manager. 2. Search MVCJQGrid and install the latest MVCJQGrid from NuGet Package Manager. Note : Recommended install latest version of JQGrid 3. Apply Installed NuGet Package into your project. Ok done the first step. Now your project already have MVCJQGrid package with it. Create your first Data Grid using MVCJQGrid First of all in order for you to start write MVCJQGrid coding, you need to add new namespace for the project. In This tutorial i will add the MvcJQGrid in web.config file : Web.Config File      <pages>           <namespaces>             <add namespace="System.Web.Helpers" />             <add namespace="System.Web.Mvc" />             <add namespace="System.Web.Mvc.Ajax" />             <add namespace