Showing posts from December, 2013

Remove Whitespace From aspx pages - Performance with page speed

Some web page have a thousand line of html code and it will increase the size of the page to download to users. It is often possible to make a content of web page fewer bytes(their size) without changing the appearance or function of the page. This approach will improve download time and makes the page load faster. The question how to make this happen without extra effort to remove the space manually and without effect the development time. This is a snippet code that you need to put in your Master page so that the code will automatically override the Render Event in The Code to put in Master Page The Attribute/Field for masterpage private static readonly Regex REGEX_BETWEEN_TAGS = new Regex(@">\s+<", RegexOptions.Compiled); private static readonly Regex REGEX_LINE_BREAKS = new Regex(@"\n\s+", RegexOptions.Compiled); The Override Method /// <summary>         /// Initializes the <see cref="T:System.Web.UI.HtmlTextWriter">&l

Understanding The Web Page Processing(End To End)

A common way to think about the Web is that there is a browser on one end of a network connection and a web server with a database on the other end.  Simplified web architecture model The simplified model is easy to explain and understand, and it works fine up to a point. However, quite a few other components are actually involved, and many of them can have an impact on performance and scalability.The next picture shows some of them for web sites based on ASP.NET and SQL Server. Web architecture components that can impact performance All of the components in picture above can introduce delay into the time it takes to load a page, but that delay is manageable to some degree. Additional infrastructure-oriented components such as routers, load balancers, and firewalls aren’t included because the delay they introduce is generally not very manageable from a software architecture perspective. In the following list, I’ve summarized the process of loading a web page. Each of these steps offers

Simple Image Resizer Tools - C# Example

This example will use the  Image Resizer Class from previous post . I have change a little bit on the class so that i can use it for my example image resizer tools. ImageResizer Tool Requirement ImageResizer tool will require user to choose the image to resize. Only JPG image supported. After that user can simply put the width and height to change the selected image width and height. User can choose is either to use aspect ratio. After Complete , user will prompt to open the new image after resize. The tools use .NET version 4. The GUI of ImageResizer Tool The Code Behind   private string _ImageName;         private string _ImageExtension;         public Form1()         {             InitializeComponent();             TPercentage.Text = "0";             tWidth.Text = "0";             THeight.Text = "0";         }         private void button1_Click(object sender, EventArgs e)         {             openFileDialog1.Filter = "JPEG Files (.JPG)|*.JPG

Example to disable save as certain file type in SSRS Report Viewer

SQL Server Reporting Service(SSRS) is a full range of ready-to-use tools and services to help you create, deploy, and manage reports for your organization, as well as programming features that enable you to extend and customize your reporting functionality. The Report Viewer provide functionality to save the report as a pdf, word and also as a excel format. Sometime organization require this feature, sometime not. This is how to disable save as function in Report Viewer(SSRS). The example will invoke methode pre-render in Report Viewer Controller. The ASPX Page <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"     Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> : : : <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat

Multiple Button in MVC 4

Many developers now have experience on ASP.NET Web development but when microsoft introduce the new solution for web development(ASP.NET Model View Controller - MVC framework) back at April 2009, not all developers like it. Because ASP.NET is just drag and drop, and easy to use different with ASP.NET MVC. Recently i have develop one web application using MVC framework and this is my first experience using it i never done it before... Just want to share some information for newbie like me to have a multiple button in one form. Sound like very easy but it is very popular in google search keyword "Multiple Button MVC" .. ok here the solution i figure out : Solution One The View(cshtml)     @using (Html.BeginForm("ActionTaken", "TestController"))       {            <button name="button" value="ActionOne" class="button" style="width: 200px;">               test1</button>            <button name="button

How to open file using their default external viewer - C#

When write the application, some of the activity is to create file, convert file, etc . After create the file, the program should prompt user to open the created file using their respective default external viewer . Letsay you create .pdf file, so the default application to open the file is Adobe Reader . The example will ask user is either user want to open file or not, if user agreed to open the file created, then the application will open file using their respective default external viewer depend on the file extension . The code    string outFilePath = File.Create("PDFFILE.pdf");                               DialogResult dr = MessageBox.Show("Open the rendered file in an external viewer?", "Open Rendered File", MessageBoxButtons.YesNo);   if (dr == DialogResult.Yes)   {       System.Diagnostics.Process.Start(outFilePath);   } By Mohd Zulkamal NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and

How to read XML file in PHP

 In this example show how to read xml file in PHP. Let say the XML file is like this : <?xml version="1.0" encoding="utf-8"?> <database> <config userdb="custinfosys" dbpass="P@ssw0rd" host="localhost:3306" database="customerinfosys"/> <defaultPassword></defaultPassword> </database> So i want to read config element and all of the attribute . Here is a sample code to read xml file : PHP -> read XML File :         //declare DOMDocument         $objDOM = new DOMDocument();         //Load xml file into DOMDocument variable         $objDOM->load("../configuration.xml");         //Find Tag element "config" and return the element to variable $node         $node = $objDOM->getElementsByTagName("config");         //looping if tag config have more than one         foreach ($node as $searchNode) {             $dbHost = $searchNode->getAttribute('host');

How to execute sql query statement in PHP

We have learn how to create connection and select database in PHP, now i will show how to run query in php. we will use "mysqli_query" or "mysql_query " method to run the query in php. Assume we already have connection and already select the database in PHP, here is a example to run the query statement. NOTE : Refer both post above to create connection and select database The Database Table CREATE TABLE IF NOT EXISTS `users` (   `userid` varchar(40) NOT NULL,   `password` varchar(80) NOT NULL,   `ROLES` varchar(40) NOT NULL,   PRIMARY KEY (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `users` -- INSERT INTO `users` (`userid`, `password`, `ROLES`) VALUES ('developersnote', 'P@ssw0rd', 'ADMIN'); The code <?php require_once('DbUtility.php'); $dbClass = new DbUtility(); $db = $dbClass->getDbConnectionMySQLi(); if (mysqli_connect_errno($db)) {     $error = '<p><br />Failed to Connect

Select Database in PHP Example

This post is a extended from previous post. Read previous here This example show how to select database schema / name in database MySQL : The DbUtil Class <?php final class DbUtility {         public static $dbHost ;     public static $dbUser ;     public static $dbPass ;     public static $dbDatabase ;     public function __construct() {          self::$dbHost = "localhost:3306";         self::$dbUser = "custinfosys";         self::$dbPass = "P@ssw0rd";         self::$dbDatabase = "customerinfosys"; // database     }     public static function getDbConnectionMySQL() {               return mysql_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse             }     public static function getDbConnectionMySQLi() {               return mysqli_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse             }         public static function setDatabaseMySQL($db){                      mysql_se

How to create mysql connection in php

 The example will show how to create connection to MySQL database using "mysql_connect" or "mysqli_connect" . The mysql_connect has been deprecated. Read here for more information. The  DbUtil Class <?php final class DbUtil {         public static $dbHost ;     public static $dbUser ;     public static $dbPass ;     public function __construct() {          self::$dbHost = "<host name>";         self::$dbUser = "<user name db>";         self::$dbPass = "<pasword db>";         }    public static function getDbConnectionMySQL() {              return mysql_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse            }     public static function getDbConnectionMySQLi() {              return mysqli_connect(self::$dbHost, self::$dbUser, self::$dbPass); //Connect to the databasse            } ?> How to use Example 1. Create php file name index to test the class 2. copy paste this code and t

How to convert List to DataTable - C#,ASP.NET

Short Description This example will show how to convert List<T> where T could be any object and convert the List<T> to DataTable. The example will use two class which is System.ComponentModel; and System.Data; Note : The Convertion class extention method must be in static because System.ComponentModel.TypeDescriptor is a static method In this example i will use . The ASPX page      <h1>         How to convert List To DataTable     </h1>     <asp:GridView ID="GridView1" runat="server">     </asp:GridView> The Code Behind        protected void Page_Load(object sender, EventArgs e)         {             List<string> listOfString = new List<string>();             for (int i = 0; i < 10; i++)             {                 listOfString.Add(i.ToString());             }                        GridView1.DataSource = Convertion.ToDataTable<string>(listOfString);             GridView1.DataBind();         } The

Tips of send or reply email for customer

Email is a one medium to communicate to others people. Mostly now days people use email to communicate with customer. I have learn something which i want to share with others  tips to send or reply email to your customer. Hopefully this note will be useful for someone. As you know, the problem with emails is that  they do not have "tone".  The interpretation of our emails is concluded by the intended recipient.  Sometimes, the interpretation differs from what we meant. As a small step to improve our customer service and professionalism, let us start with the ethics of emails.  There's a lot being written on the Net but I listed down here the common ones. Tips of send or reply email to customer Take care of your grammar and spelling - people may perceive you as sloppy. Use salutation - Dear Sir... Dear Madam... Careful with capital letters.  People may interpret your words as screaming or yelling. Think twice on who you want to C.C. Big bosses may be annoyed with unnecessa

C#: Retrieve Machine Information

This is a example how to get Machine Information in C#. The example will use Class ManagementObjectSearcher --> System.Management Note: The code will only work on Window 32 bit, If you are using 64 bit Operation system, you need to comment few Method GetTotalPhysicalMemory,GetTotalVirtualMemory,and GetAvailableVirtualMemory. The MachineInfo Class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; using System.Net; using System.Diagnostics; namespace GenericErrorHandling {     class MachineInfo     {         ManagementObjectSearcher query;         ManagementObjectCollection result;         string responseString;         int responseInt;         public string GetMachineName()         {             return Environment.MachineName.ToUpper();         }         public string GetOSVersion()         {             return Environment.OSVersion.VersionString;         }         public string GetProcessorCount()         {             r

How to Upload CSV File into database MSSQL

Brief Description The post will show code example how to upload CSV file data into Database and insert bulk record into SQL server database. Before we start the example, create the table in the database : SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[CSVTABLE](     [ID] [int] NOT NULL,     [NAME] [varchar](40) NOT NULL,     [ADDRESS] [varchar](80) NOT NULL,     [POSKOD] [varchar](15) NOT NULL,     [NOTEL] [varchar](15) NOT NULL,  CONSTRAINT [PK_CSVTABLE] PRIMARY KEY CLUSTERED (     [ID] ASC )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO After create the table on the database, now we can proceed on the code example. Let say the csv file like this : The CSV File 1,NAMA1,ADDRESS1,POSKOD1,NOTEL1 2,NAMA2,ADDRESS2,POSKOD2,NOTEL2 3,NAMA3,ADDRESS3,POSKOD3,NOTEL3 4,NAMA4,ADDRESS4,POSKOD4,NOTEL4 5,NAMA5,ADDRESS5,POSKOD5

C#: use EventLog to store error message example

EventLog lets you access or customize Windows event logs, which record information about important software or hardware events. Using EventLog , you can read from existing logs, write entries to logs, create or delete event sources, delete logs, and respond to log entries. You can also create new logs when creating an event source. The example will show how to use event log in your application The Code private void button1_Click(object sender, EventArgs e)  {     try     {         string[] a = new string[3];         a[4] = "test";     }     catch (Exception ex)    {         LogError(ex);     }  } public void LogError(Exception ex)  {     string EventLogSourceName = "Example Log Error";     int EventLogErrorCode = 99;     string msg = "The application encountered an unknown error:";     msg += "\r\nExecuting Method: " + new System.Diagnostics.StackFrame(1, false).GetMethod().Name;     msg += "\r\nError Message: " + ex.Message;    

How to show hide form(Desktop application) C#

Usually when programmer to hide the form from User they will use this command : this.Hide(); But the problem to unhide that form..So the this is a solution to unhidden the form.. Scenario You have 2 Form, Form1 and Form2. the situation is form2 was hide and you want to show it back  foreach (Form form in Application.OpenForms) {      if (form is Form2)      {        form.Show();          break;      } } By Mohd Zulkamal NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

How to create XML file using C#

XML is a platform independent language, so the information formatted in XML can be used in any other platforms (Operating Systems). Once we create an XML file in one platform it can be used in other platforms also. In order to creating a new XML file in C#, we are using XmlTextWriter Class . The class takes FileName and Encoding as argument. Also we are here passing formatting details . The following C# source code creating an XML file product.xml and add four rows in the file The Code using System; using System.Data; using System.Windows.Forms; using System.Xml; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { XmlTextWriter writer = new XmlTextWriter("product.xml", System.Text.Encoding.UTF8); writer.WriteStartDocument(true); writer.Formatting = Formatting.Indented; writer.In