Showing posts from October, 2013

Convert Type to SqlDataType and SqlDataType to Type C#

Type conversion basically involve casting and convert from one type to another. You can try the Type conversion by following this web site . Today i want to share code to convert from Type to SqlDataType. This method can be used for example to add parameters to SqlCommand based on DataTable column DataType, see example below : SqlCommand dbComm = new SqlCommand("<sql statement>",<sql connection>); dbComm.Parameters.Add("<parameter name>", < sql Data Type>]).Value  = "test"; what about if you have DataTable and you want to automatically loop into column of datatable and and automatically assign Sql Data Type based on Column DataType of data table ..?There is nothing method or casting that available to do this, but after i googling about converting / casting DataType to SqlDataType, the result seem like impossible to done in .net . C# Parse SqlDbType Convertion C# data types to SQL Server data types   Convert DataColumn.DataType to Sq

Modal Popup Message Box ASP.NEt C# Example

Message box is a must in a web application right now. I will show example how to create message box like picture above. Requirement to try this example : AjaxControl Toolkit User Control  :  MessageBox.ascx Sample Page To call Message Box : MessageModalPopup.aspx The MessageBox.ascx  <link href="../messageBoxStyle.css" type="text/css" rel="Stylesheet" /> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> <asp:ModalPopupExtender BackgroundCssClass="modalBackground" ID="ModalPopupExtender1"     Drag="true" DropShadow="true" PopupControlID="Panel1" TargetControlID="Button2"     runat="server"> </asp:ModalPopupExtender> <asp:Button ID="Button2" runat="server" Text="Button" Style="display: none;" /> <asp:Panel ID="Panel1" runat="server

Auto Complete Example ASP.NET AjaxToolkit C#

Auto complete is one powerful feature in modern web application. It is helping people to get the suggestion what are the word to put in the textbox. Today i want to show example how to use AutoComplete feature in AjaxToolkit Asp.Net The List of requirement : AjaxToolkit library AutoCompleteTextBox.aspx Page DataAutoComplete.asmx Web services The AutoCompleteTextBox.aspx Page :  <%--Script Manager--%>     <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">     </asp:ToolkitScriptManager>     <%--The Textbox--%>     <asp:TextBox ID="TextBox1" runat="server" Width="259px"></asp:TextBox>     <%--Auto Complete Textbox Extender Controller--%>     <asp:AutoCompleteExtender ID="autoComplete1" runat="server" EnableCaching="true"         BehaviorID="Auto" MinimumPrefixLength="2" TargetControlID="TextBox1"         ServicePath=&

How to create zip file to download in JSP- Servlet

Hye, my previous post show that how to download zip file in ASP.NET ,. In this tutorial i will show the same thing, but in Jsp-Servlet. Note : In this tutorial i will use this library :- JSTL 1.1  The JSP File  <%@ taglib prefix="c" uri=""%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">         <title>Download File As ZIP File</title>     </head>     <body>        <h1>Download File As ZIP File</h1>         ${DownloadMessage}         <br/>         <form action="<c:url value="/downloadFileServletZip" />" method="post" >             Default Path is server to download is D:\JAVA\dist\Output\             <input type="submit" name="bDownload"

How to create zip file to download - C#

Today i want to show you how to create file on the fly from server side and pass it to client to download. The idea is to create the zip file when the button clicked, and then save the zip file and pass the zip file to client side. After file finish to download, you may be delete the zip file to reduce the resource of the server. Some application will allow user to download multiple file, but to download file by clicking one by one button is not necessary as you can zip the file and download all the file as one single zip file. In this tutorial i will use library DotNet Zip Library : This is The Sample program , you can freely enhance or change the part of the program to meet your program requirement. The ASPX Page  <asp:Label ID="Label1" Text="DirectoryPath : " runat="server"></asp:Label>     <asp:TextBox ID="TextBox1" runat="server" Height="25px" Width="362px"></asp:TextBox>     <br />

Date Time Conversion utility Java

In this post, I will like to share a sample code snippet for date-time manipulation in Java. Convert hour from integer to string Scenario: Converts hour from integer to String. If the hour is a single digit, the leading zero will be added. public static String getHourString(int localHourNumber) {         if ((localHourNumber > 23) || (localHourNumber < 0)) {             return "";         }         if ((localHourNumber >= 0) && (localHourNumber <= 9)) {             return "0" + localHourNumber;         }         return String.valueOf(localHourNumber);     } Convert minute from integer to string  Scenario: Converts minute from integer to String. If the minute is a single digit, the leading zero will be added. public static String getMinuteString(int localMinuteNumber) {         if ((localMinuteNumber > 59) || (localMinuteNumber < 0)) {             return "";         }         if ((localMinuteNumber >= 0) && (localMinute

How to read all folder and subfolder path C#

Today i want to show how you can get folder path and all subfolder path. The process is more efficient and faster because im using IEnumerable type to determine if path has sub directory or not. I write this example in c# using window form. Here is my winform GUI :   The sample Output ---------------------------------- Directory List Start Path : C:\Android Project ---------------------------------- List file and directory Directory and Subdirectory Name C:\Android Project\FirstProject C:\Android Project\FirstProject\.metadata C:\Android Project\FirstProject\.metadata\.plugins C:\Android Project\FirstProject\.metadata\.plugins\org.eclipse.cdt.core C:\Android Project\FirstProject\.metadata\.plugins\org.eclipse.cdt.make.core C:\Android Project\FirstProject\.metadata\.plugins\org.eclipse.core.resources C:\Android Project\FirstProject\.metadata\.plugins\org.eclipse.core.runtime C:\Android Project\FirstProject\.metadata\.plugins\org.eclipse.debug.core C:\Android Project\FirstProject\.metada

How to read XML using LINQ - ASP.NET C#

LINQ -  stand for Language Integrated Query is powerful features that extend the query capability to the language syntax in C# or Visual basic. In this tutorial, I will show one example of how to read XML file using Linq. Checklist : Create one aspx page name "ReadxmlUsingLinq.aspx". Create one xml file name "XmlDataTest.xml" The XmlDataTest.xml  <?xml version="1.0" encoding="utf-8" ?> <root>   <TransactionName Description="Transaksi ASB">     <MENU Name="Inquiry">       <ITEMS TargetUrl="/Transaction/Default.aspx" DESCRIPTION="DefaultPage" ShortcutKey="Ctrl + H,1"></ITEMS>       <ITEMS TargetUrl="/Transaction2/Default.aspx" DESCRIPTION="DefaultPage2" ShortcutKey="Ctrl + H,2"></ITEMS>       <ITEMS TargetUrl="/Transaction3/Default.aspx" DESCRIPTION="DefaultPage3" ShortcutKey="Ctrl + H,3"&g

How to create captcha image in C#

The word CAPTCHA (stand for "Completely Automated Public Turing test to tell Computers and Humans Apart") is one mechanism that used in a web application to determined if a visitor that accesses the web application is a human or bot. This is because the captcha contains some words as Images that required users to enter the same word in the web application form to complete the process.  The captcha also used to prevent bots from automatically access the web page and do some SPAM thing on the web page. Today I will show a tutorial to create a Captcha image in the application : Checklist : Create one dummy aspx page name " CaptchaImage.aspx ". Create Captcha class name " CaptchaClass.cs ". Create Page dummy to create a captcha image name " Captcha.aspx ". The CaptchaImage.aspx page <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CaptchaImage.aspx.cs" Inherits="Captcha.CaptchaImage" %>

Page Asynchronous and Synchronous Postback page example - ASP.NET

Asynchronous postback and synchronous postback is a process submission back to the server. Only update panels elements are sent back to the server if you use async postback(AJAX) while synchronous postback will be sent all page content to the server back. Today I will create one example to differentiate between async postback and sync postback. The ASPX page Register the ajax toolkit script manager : <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </asp:ToolkitScriptManager> Update Panel Content : <asp:UpdatePanel ID="UpdatePanel1" runat="server">         <ContentTemplate>             <asp:Button ID="Button1" runat="server" Text="Do AsyncPostback Update" OnClick="Button1_Click" />             <asp:Button ID="Button2" runat="server" Text="Do Postback Update" OnClick="Button2_Click" />             <