Archive for the ‘Javascript’ Category

Creating MAC OS X Lion Login and Desktop using Css3

This post is taken from http://www.alessioatzeni.com/blog/mac-os-x-lion-with-css3/

Alessio Atzeni wanted to create with only use of CSS3 the boot, the login page and finally the desktop of the Mac OS X Lion.

This is the first release and as you will see not everything is fully functional and at least as regards the desktop. In the next release Alessio Atzeni will implement new icons and new features while we examine what we have today.
Boot

This is simply the Mac OS X Lion boot. This section is simply composed by a CSS3 keyframes animation.
It has a logo (created in Photoshop) and a simple loader (fake loading). After the animation, dissolves the section to show the login section.

mac-boot
Login

This section mainly consists of a clock, two images (logos and avatars user name), two backgrounds and a password input field.
Alessio Atzeni used javascript only for the clock, create a fake login and when the password is valid Alessio Atzeni added some class to fix the desktop section and remove permanently the section login animation.

Thanks to the :target pseudo-class can be passed from one section to another. Regarding the rest is all CSS 3, such as hide/show the input field when you click on the avatar, same goes for the appearance of the tooltip when you click on the input field.

The animation of password error is connected via javascript but the animation is created using CSS3. The pseudo-class target has its limits and then to fix those small weaknesses, once you enter your password, javascript sets the desktop as the main section.

mac-login
Desktop

Finally here we have in our desktop. As mentioned previously this is only the first version, and consequently still missing several features that Alessio Atzeni will implement in the next release. Alessio Atzeni use javascript only for the clock and the jQuery UI Draggable library to have a draggable windows.

For the rest is all CSS3 excluding the background image and icons.

mac-dock
About this Project

Here Alessio Atzeni will list what he used for this project.
Modern Browser Supported

To see this experiment you will need a browser that supports CSS3 Keyframes Animations, so the choice is Firefox, Safari, or Chrome.
HTML5 and CSS3

For this project he used HTML5 and the unique capacity of CSS3.
Javascript

The use of JavaScript is for the clock, and to add a fix to the section desktop once you get the validation.
Draggable Window

Alessio Atzeni used this library jQuery UI Draggable.
Images and other decoration

Finally he used images for logos, user-avatar, spinner loading, cursors, background images, icons and window buttons.
Conclusion and Next Release

At the end of this experiment he realized the potential and limitations of CSS3, but thanks to the use of javascript (although to a limited) you can really get something unique.

Regarding the next release he plan to add the dock, delete and appears the windows if you click on a link on the menu only through the use of CSS. Optimize the code for better performance.

Alessio Atzeni hope that this experiment can be useful, and please you in your study, if you have any questions please do not hesitate to write.

Thank you all for your support.

Designing a vimeo player for website

Coding a vimeo Player is not a hard task but maitaining its skin and style is a very deficult task. any one can design a small vimeo player just by coding some of the lines like the lines given below and the vimeo player is ready for you.

Note :- Please replace &lt; by < and &gt; by > before making it as your player. the code is as follows.

&lt;div style=”width:504px; height:412px; overflow:hidden;”&gt;
&lt;object&gt;
&lt;param name=”allowfullscreen” value=”true” /&gt;&lt;param name=”wmode” value=”opaque” /&gt;
&lt;param name=”allowscriptaccess” value=”always” /&gt;
&lt;param name=”movie” value=”http://vimeo.com/moogaloop.swf?clip_id=2285902&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1&#8243; /&gt;
&lt;embed src=”http://vimeo.com/moogaloop.swf?clip_id=2285902&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1&#8243; type=”application/x-shockwave-flash” allowfullscreen=”true” wmode=”opaque” allowscriptaccess=”always” width=”504″ height=”412″&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;/div&gt;

Now the vimeo player has been designed.

Best 25 Free Online Fax Services

It can be quite expensive to keep separate and dedicated Fax machines for different sections of big offices. Every department want privacy of data and want to shed the dependence on one particular fax machine.

But on the other hand, when many employees are at freedom of working from home and others are traveling continuously to every corner of world, keeping Fax machines at every place is next to impossible. Many of you don’t know that we can look up to online fax service in such a right spot.

Although most of these online fax services are not free to use but you can always opt for the trial version before actually buying the paid version. Today we have collected 25 Best Free Online Fax Services which will give you a whole bunch of happiness. You will no more be on the mercy of the Fax machine being kept on the reception area of your office. These Online Fax Services send Fax to you in form of emails so you can check the fax at your ease. Please have a look at below mentioned 25 Best Free Online Fax Services (Trial Versions) and make your life simple and better.

If you like this article, you might be interested in check the collection of website for Free Stock Photos,Make a Cartoon of Yourself, Finding a Perfect Domain Name, Download Free Fonts, Have Fun With Your Pics, Free Textures, and Getting Free Vector Art Images.

eFax

Send & receive faxes by email and you will also get a local fax number. You can check it with a 30 day trial offer.

eFax

More Information on eFax

K7

Its a web-based unified messaging system that channels your free voicemail and fax messages directly to your e-mail. K7 Unified Messaging provides you with a free phone number.

K7

More Information on K7

faxZERO

In its free version, you will have an Ad on the cover page,you can Fax 1 document — max 3 pages and Max 2 free faxes on per day basis

faxZERO

More Information on faxZERO

My1Voice

My1Voice is a virtual phoone. You can check a 30 day trial version and receive faxes from your my1voice number along with other features.

My1Voice

More Information on My1Voice

PamFax

With a trial version of PamFax, you can send some faxes for free. Iit supports many file formats in addition to PDF and DOC files.

PamFax

More Information on PamFax

ScanR

It’s a digital scanner and fax in your pocket! Your phone is suddenly a business center – scan, print and fax wherever you go. Scan documents to turn them into digital files you can store, share, and fax.

ScanR

More Information on ScanR

freefax

freefax

More Information on freefax

Interpage

This is a free service offered by Interpage to demonstrate and promote our fast, robust, and reliable email-to-fax and other fax delivery services. Using this service, you may send a fax for free to any US/Canada-based fax machine, for delivery to the destination fax which you specify

Interpage

More Information on Interpage

MaxEmail

Send & Receive Faxes Without Buying a Fax Machine or an Expensive Dedicated Phone Line

MaxEmail

More Information on MaxEmail

RapidFAX

RapidFAX combines the utility of fax with the ease of email to meet the needs of the small office and home office.

RapidFAX

More Information on RapidFAX

smartfax

Send fax from email to any fax number. Merge the convenience of email with fax.

smartfax

More Information on smartfax

TrustFax

With Trustfax, no Fax Machine or Phone Line Required and you get a Toll-Free and Local Fax Number.

TrustFax

More Information on TrustFax

VIF Internet

ervice limited to sending free faxes to the city of Montreal, Canada.

VIF Inter

More Information on VIF Internet

Metro Fax

With metro fax you can send high quality faxes from anywhere in the world using your web browser, no need for a fax machine, to a wide range of locations.

Metro Fax

More Information on Metro Fax

PopFax

You will get an account to send and receive fax, with a local fax number you can choose from over 500 cities in 20 countries. What more you can even go for a mobile fax service.

PopFax

More Information on PopFax

FaxFreedom

Fax machines are expensive and take up too much room. With FaxFreedom you can now simply send and receive faxes from any computer.

FaxFreedom

More Information on FaxFreedom

nextiva

With Nextiva vFAX all you need is an Internet connection in order to send and receive faxes. Our online fax service is easy to use, affordable and gives you great flexibility.

nextiva

More Information on nextiva

MyFax

MyFax is a fax service that lets you send and receive faxes through your email, the web, or smart phone.

MyFax

More Information on MyFax

Wonderfax

WonderFax is a free UK fax number that pick up your fax, converts them to a pdf file and emails it back to you as an attachment. So there is no need for fax lines or fax machines.

Wonderfax

More Information on Wonderfax

FaxOrama

FaxOrama supports multiple document formats like DOC, DOCX, RTF, GIF, JPG, JPEG, PDF, TIF, XLS, XLSX, TXT, PNG, BMP and WPS. You can also opt for a restricted sending option but an ad free free version.

FaxOrama

More Information on FaxOrama

Superfax

You can get a Fax Number in Paris, Los Angles or London for Free for a week. And See how it works.

Superfax

More Information on Superfax

MESSAGENET

It gives you 90 days trial period to check the service. You can both receive as well as send fax free till this time

MESSAGENET

More Information on MESSAGENET

GotFreeFax

It lets user send free fax online to the US and Canada without ads

GotFreeFax

More Information on GotFreeFax

that’s it.

Top 10 online Fax Services

A fax (short for facsimile) is a document sent over a telephone line. Although businesses usually maintain some kind of fax capability, the technology has faced increasing competition from Internet-based alternatives. However, fax machines still retain some advantages, particularly in the transmission of sensitive material which, if sent over the Internet unencrypted, may be vulnerable to interception. In many corporate environments, standalone fax machines have been replaced by “fax servers” and other computerized systems capable of receiving and storing incoming faxes electronically, and then routing them to users on paper or via an email (which may be secured). Such systems have the advantage of reducing costs by eliminating unnecessary printouts and reducing the number of inbound analog phone lines needed by an office.

Don’t have a fax machine ? No problem. You can use the Internet to send a free fax to any number all over the world. Here You find 10 websites for free online fax services.

1 . Myfax

  • Website : http://myfax.com
  • Fax Limitation : Unlimited
  • Support : Text and Document (.doc , .pdf etc)
  • Fax Receive : No
  • Registration Requirement : No
  • Country Limitation : Available for 41 Country’s

2 . Pamfax

  • Website : http://www.pamfax.biz
  • Fax Limitation : Unlimited
  • Support : Text and Document
  • Fax Receive : Yes
  • Registration Requirement : Yes
  • Country Limitation : Worldwide

3 . Faxzero

  • Website : http://faxzero.com
  • SMS Limitation : 2 faxes per day for free
  • Support : Text and Document
  • Registration Requirement : No
  • Country Limitation : Unknown

4 . Freepopfax

  • Website : http://www.freepopfax.com
  • Fax Limitation : Unlimited
  • Support : Text and Document
  • Registration Requirement : No
  • Country Limitation : Available for 48 Country’s

5 . Gotfreefax

  • Website : http://www.gotfreefax.com
  • Fax Limitation : 2 faxes per day for free
  • Support : Text and Document
  • Registration Requirement : No
  • Country Limitation : Worldwide

6 . Freefaxbutton

  • Website : http://www.freefaxbutton.com
  • Fax Limitation : 2 faxes per day for free
  • Support : Text only
  • Registration Requirement : No
  • Country Limitation : Available for 65 Country’s

7 . Fax1

  • Website : http://www.fax1.com
  • Fax : $1 for free use
  • Support : Text and Document
  • Fax Receive : Yes
  • Registration Requirement : Yes
  • Country Limitation : Worldwide

8 . Freefax

  • Website : http://freefax.1888usa.com
  • Fax Limitation : Unlimited
  • Support : Text only
  • Registration Requirement : No
  • Country Limitation : Available for 28 Country’s

9. Sendfreefax

  • Website : http://sendfreefax.net
  • Fax Limitation : Unlimited
  • Support : Text only
  • Registration Requirement : No
  • Country Limitation : Worldwide

10 . Faxaway

  • Website : http://www.faxaway.com
  • Fax Limitation : Unknown
  • Support : Text and Document
  • Fax Receive : Yes
  • Registration Requirement : Yes
  • Country Limitation : Worldwide

A detailed Discussion about CSS3 : border-image

Another exciting new border feature of CSS3 is the property border-image. With this feature you can define an image to be used instead of the normal border of an element. This feature is actually split up into a couple of properties: border-image and border-corner-image. These two values are shorthands for:

  • border-image:
    • border-top-image
    • border-right-image
    • border-bottom-image
    • border-left-image
  • border-corner-image:
    • border-top-left-image
    • border-top-right-image
    • border-bottom-left-image
    • border-bottom-right-image

border-image currently works in Safari and Firefox 3.1 (Alpha). The syntax to use it is:

border-image: url(border.png) 27 27 27 27 round round;

Which results in:

Lorem ipsum dolor sit amet.

Or:

border-image: url(border.png) 27 27 27 27 stretch stretch;

Which then results in:

Lorem ipsum dolor sit amet.

For those of you not so lucky as to be able to see this, here are screenshots of the two examples.

Number one:
border-image first example
Number two:
border-image second example

The new CSS3 property border-image is a little tricky, but it can allow you to create flexible boxes with custom borders (or drop shadows, if that’s your thing) with a single div and a single image. In this article I explain how the border-image shorthand property works in today’s browsers.

The basic idea

The border-image shorthand property has 3 parts:

border-image: url(border-image.png) 25% repeat;

Essentially, these allow you to specify:

  1. An image to use as the border
  2. Where to slice that image, dividing the image into 9 sections
  3. How the browser should apply those sections to the edges of your element

The pertinent details

Let’s look at each part of the process in a little more detail. The first part is easy, and is familiar from the background-image property. For demonstration purposes I’ll use this image, which is 100px x 100px:

A border-image

Slicing your image

The second part can have from one to four values, much like the border-width property, and they are specified in the same order: top, right, bottom, left. You can use percentages or pixels. Strangely, the percentages require the “%”, while pixels should be listed without the “px”:

border-image: url(my-image.gif) 25% 30% 10% 20% repeat;
border-image: url(my-image.gif) 25 30 10 20 repeat;

In this case, since my image is 100px x 100px, the two rules above are equivalent – they slice the image in the same places. I’ve added some dimensions on my image to demonstrate:

A border-image

Repeat, Round, Stretch

border-image will always place the corner sections of your image into the corresponding corners of your element box, but the third part of the shorthand rule tells the browser how to treat the middle sections of your image — the ones that will go along the edges of your element. Repeat (repeat, or tile, the image) and stretch (stretch, or scale, the image) are pretty self-explanatory. Round means tile the image but only so that a whole number of tiles fit, and otherwise scale the image. Right now, Safari and Chrome interpret round asrepeat. There can be up to two values: one for the top and bottom edges of the element, and one for the left and right. Here’s an example with the top/bottom value set to repeat, and the left/right value set to stretch:

#example-one {
 border-width:25px 30px 10px 20px;
 -moz-border-image:url("border-image.png") 25 30 10 20 repeat stretch;
 -webkit-border-image:url("border-image.png") 25 30 10 20 repeat stretch;
 border-image:url("border-image.png") 25 30 10 20 repeat stretch;
}

Screenshot for Example One

LIVE DEMO, RSS READERS CLICK OVER TO SEE. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu arcu non dui consequat vestibulum non vitae eros. Donec imperdiet lorem at mi rhoncus lacinia. Phasellus porttitor ligula eu justo condimentum eget placerat arcu pharetra. Proin fringilla vulputate eros in accumsan. Sed mi nibh, pulvinar eu sollicitudin ut, feugiat non ipsum. In ornare, quam sit amet tempor suscipit, erat odio suscipit nisi, eu gravida nisl orci ut arcu. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Border-width

border-image won’t do anything if you don’t specify a width for your border. For browsers that understand border-image, your image slices will be scaled to the specified width. If you use the border shorthand property, it provides a nice fallback for browsers that don’t:

#example-two {
 border:50px double orange;
 -moz-border-image:url("border-image.png") 25 30 10 20 repeat;
 -webkit-border-image:url("border-image.png") 25 30 10 20 repeat;
 border-image:url("border-image.png") 25 30 10 20 repeat;
}

Screenshot of Example Two

LIVE DEMO, RSS READERS CLICK OVER TO SEE.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu arcu non dui consequat vestibulum non vitae eros. Donec imperdiet lorem at mi rhoncus lacinia. Phasellus porttitor ligula eu justo condimentum eget placerat arcu pharetra. Proin fringilla vulputate eros in accumsan. Sed mi nibh, pulvinar eu sollicitudin ut, feugiat non ipsum. In ornare, quam sit amet tempor suscipit, erat odio suscipit nisi, eu gravida nisl orci ut arcu. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Or you can specify each width individually (in this example I’ve specified widths such that the image slices aren’t scaled at all):

#example-three {
 border-color:orange;
 border-style:double;
 border-width:25px 30px 10px 20px;
 -moz-border-image:url("border-image.png") 25 30 10 20 repeat;
 -webkit-border-image:url("border-image.png") 25 30 10 20 repeat;
 border-image:url("border-image.png") 25 30 10 20 repeat;
}

Screenshot of Example Three

LIVE DEMO, RSS READERS CLICK OVER TO SEE. dolor sit amet, consectetur adipiscing elit. Aenean eu arcu non dui consequat vestibulum non vitae eros. Donec imperdiet lorem at mi rhoncus lacinia. Phasellus porttitor ligula eu justo condimentum eget placerat arcu pharetra. Proin fringilla vulputate eros in accumsan. Sed mi nibh, pulvinar eu sollicitudin ut, feugiat non ipsum. In ornare, quam sit amet tempor suscipit, erat odio suscipit nisi, eu gravida nisl orci ut arcu. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Using a plain border at the same widths as your border-image won’t always be ideal, however, so you may want to use conditional stylesheets to give IE some different border styles altogether.

Browser quirks

Predictably, IE doesn’t understand anything of border-image. Browsers that do support border-image only support the shorthand property, not all the individual properties that aredescribed in the spec. Some potentially useful properties aren’t supported at all, especiallyborder-image-outset, which would solve this problem.

Also, the default behavior is supposed to be to discard the center section of the image, and use the ‘fill’ keyword on the border-image-slice property to preserve it:

The ‘fill’ keyword, if present, causes the middle part of the border-image to be preserved. (By default it is discarded, i.e., treated as empty.) (Read the spec)

But the current browser behavior is to preserve the middle, and there is no way to turn it off. Thus, if you don’t want your element’s content area to have a background, the center section of your image must be empty. However, you can use this filling behavior to your advantage, to create a box with a fancy border and background, with only one image.

Interactive demo

I built a border-image demo page to help me get my head around this complicated new set of CSS3 properties. You can pick an image, specify repeat, round, or stretch, and adjust the border-width and slicing. Enjoy!

Examples in the wild

CSS3 makes it possible to specify an image as an element’s border, instead of just a solid color. While on the surface this doesn’t seem particularly interesting, the way the property works makes it more than that which meets the eye. The border-image property lets you specify a single image for the purpose and then slices that image to create the desired border effect. Yes, CSS is slicing now. border-image is currently supported in all the modern browsers to various degrees except IE (as of IE9). The shorthand syntax is:

border-image: url(image.png) 25 40 12 10 stretch;

Where:

  • url: The image that should be used as the border image.
  • slicevalues: Up to four numbers that specify where the browser should slice the image:
    • The 1st value sets the offset of the first horizontal cut from the top of the image. For pixel units, do NOT include the “px” suffix.

    • The 2nd value sets the offset of the second vertical cut from the right edge of the image.

    • The 3rd value sets the offset of the third horizontal cut from the bottom of the image.

    • The 4th value sets the offset of the fourth vertical cut from the left edge of the image.

  • stretch: How the slices should be oriented inside the element’s border. Valid values are “stretch”, “repeat”, “round”, or “space”.

For slicevalues, if only one number is defined, the same value will be used for all 4 cuts. If 2 numbers are defined, the first is used for the top and bottom cuts, and the second the left and right cuts. Regardless, 4 cuts are made to the image in total, and the browser ends up with 9 slices that it uses to put together the border image of an element. Each slice is used to fill the corresponding edges of the element’s border, with the center slice covering the element itself (and should be made transparent in most cases).

This post isn’t about a detailed description of border-image– that will have to be for another post. For this post, what I want to demonstrate is how to use this property to easily add image frames to containers on your page. First, create the image you’d like to use as the frame; here I’ve whipped up 2 simple frames to illustrate the technique:

  

Note that both images above have a transparent inside so the content they are framing can show through.

Now, to the heart of the matter- to add an image border to an element, define the border-image property with slicevalues that cut up the image as desired. Also define a border-width property echoing those values. Enough talk, to some examples now! Note that the below examples do not work in IE (as of IE9):

Example 1:

Found across much of the tropics, the coconut is known for its great versatility as seen in the many domestic, commercial, and industrial uses of its different parts. Coconuts are part of the daily diet of many people. Its endosperm is known as the edible “flesh” of the coconut; when dried it is called copra. The oil and milk derived from it are commonly used in cooking and frying; coconut oil is also widely used in soaps and cosmetics. The clear liquid coconut water within is a refreshing drink and can be processed to create alcohol. The husks and leaves can be used as material to make a variety of products for furnishing and decorating. It also has cultural and religious significance in many societies that use it. -Wikipedia

CSS:

.imageborder{
border-width: 20px;
-moz-border-image: url(frame.gif) 20 stretch; /*Mozilla version*/
-webkit-border-image: url(frame.gif) 20 stretch; /*Webkit version*/
-o-border-image: url(frame.gif) 20 stretch; /*Opera version*/
-ms-border-image: url(frame.gif) 20 stretch; /*IE syntax when it does support this prop*/
border-image: url(frame.gif) 20 stretch; /*Standard version*/
}

Markup:

<div style=”width:50%;min-height:150px”>
Content text here…
</div>

Example 2:

CSS: Same as above.

Markup:

<img src=”coconut.jpg” />

Example 3:

CSS:

.imageborder2{
border-width: 25px 30px;
-moz-border-image: url(frame2.png) 25 30 stretch;
-webkit-border-image: url(frame2.png) 25 30 stretch;
-o-border-image: url(frame2.png) 25 30 stretch;
-ms-border-image: url(frame2.png) 25 30 stretch;
border-image: url(frame2.png) 25 30 stretch;
}.

Markup:

<div style=”width:470px;height:300px;background:url(ocean_thumb.jpg) center center no-repeat”>
</div>

 

If you have other examples on live sites, I’d love to see them. Leave a link in the comments!

How to get a Paypal Button on webpage

Write the below given code into an HTML file where you want to add a donation button.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick"/>
    <input type="hidden" name="business" value="donations@example.com"/>
    <input type="hidden" name="item_name" value="School Fund"/>
    <input type="hidden" name="item_number" value="2011"/>
    <input type="hidden" name="amount" value="50.00"/>
    <input type="hidden" name="no_shipping" value="2"/>
    <input type="hidden" name="no_note" value="1"/>
    <input type="hidden" name="currency_code" value="USD"/>
    <input type="hidden" name="tax" value="0"/>
    <input type="hidden" name="bn" value="PP-DonationsBF"/>
    <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" 
        border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>

where input type are fields to have values for your expectations, the name business shows the value for the type of business, item_name shows the type of item, amount for the value of item, and so on …

And you are done with a button for your Paypal payment gateway.

And for the rest making a change in value for the line <input type=”hidden” name=”bn” value=”PP-DonationsBF”/>,
you can switch between several types of alternatives:

  1. <input type=”hidden” name=”bn” value=”PP-SubscriptionsBF”/>
  2. <input type=”hidden” name=”bn” value=”PP-DonationsBF”/>
  3. <input type=”submit” value=”PayPal”/>
  4. <input type=”hidden” name=”bn” value=”PP-BuyNowBF”/>
  5. <input type=”hidden” name=”bn” value=”PP-ShopCartBF”/>

Hence your Paypal gateway is ready to face the world of payments.

Exporting only selected or checked rows and records from grid to Word or Excel sheet using asp.net

Introduction: 
Here I will explain how to export only selected or checked rows or records from gridview to Word or Excel sheet using asp.net.
Description:

After all the concepts one of the user has asked me a question i.e. how to export gridview records to excel/word based on checkbox selection in gridview. To implement this one first design one table in database as shown below and give name as “UserInformation” 

ColumnName

DataType

UserId

Int(set identity property=true)

UserName

varchar(50)

LastName

varchar(50)

Location

varchar(50)

After completion of table creation enter some dummy data and design aspx page like this

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head id=”Head1″ runat=”server”>

<title>Export Selected records from Gridview to Excel/ Word</title>

<style type=”text/css”>

.GridviewDiv {font-size100%font-family‘Lucida Grande’, ‘Lucida Sans Unicode’, Verdana, Arial,Helevetica, sans-serifcolor#303933;}

Table.Gridview{border:solid 1px #df5015;}

.Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em0.5em 0.5em 0.5em;text-align:center}

.Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em0.5em;}

.Gridview tr{colorBlackbackground-colorWhitetext-align:left}

:link,:visited { color#DF4F13text-decoration:none }

.highlight {text-decorationnone;color:black;background:yellow;}

</style>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<table>

<tr>

<td align=”right”>

<asp:ImageButton ID=”btnExcel” runat=”server” ImageUrl=”~/ExcelImage.jpg”

onclick=”btnExportExcel_Click” />

<asp:ImageButton ID=”btnWord” runat=”server” ImageUrl=”~/WordImage.jpg”

onclick=”btnWord_Click” />

</td>

</tr>

<tr>

<td>

<div class=”GridviewDiv”>

<asp:GridView ID=”gvdetails” runat=”server” AutoGenerateColumns=”False” AllowPaging=”True”

AllowSorting=”true” Width=”540px” PageSize=”10″ CssClass=”Gridview” 

DataKeyNames=”UserId”OnPageIndexChanging=”gvdetails_PageIndexChanging” >

<HeaderStyle BackColor=”#df5015″ />

<Columns>

<asp:TemplateField>

<ItemTemplate>

<asp:CheckBox ID=”chkSelect” runat=”server” />

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField=”UserId” HeaderText=”UserId” />

<asp:BoundField DataField=”UserName” HeaderText=”UserName” />

<asp:BoundField DataField=”LastName” HeaderText=”LastName” />

<asp:BoundField DataField=”Location” HeaderText=”Location” />

</Columns>

</asp:GridView>

</div>

</td>

</tr>

</table>

</div>

</form>

</body>

</html>

Now in code behind add following namespace references

using System;

using System.Collections;

using System.Data;

using System.Data.SqlClient;

using System.IO;

using System.Web.UI;

using System.Web.UI.WebControls;

After that write the following code in code behind
C# Code


protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

BindGridData();

}

}

/// <summary>

/// This Method is used to bind gridview

/// </summary>

private void BindGridData()

{

SqlConnection con = new SqlConnection(“Data Source=SD;Integrated Security=true;Initial Catalog=MySampleDB”);

SqlCommand cmd = new SqlCommand(“select * from UserInformation”, con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

gvdetails.DataSource = ds;

gvdetails.DataBind();

}

public override void VerifyRenderingInServerForm(Control control)

{

/*Verifies that the control is rendered */

}

protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

SaveCheckedValues();

gvdetails.PageIndex = e.NewPageIndex;

BindGridData();

PopulateCheckedValues();

}

/// <summary>

/// This event is used to export gridview data to Excel document

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

protected void btnExportExcel_Click(object sender, EventArgs e)

{

ExportFunction(“attachment;filename=GridViewExport.xls”“application/vnd.ms-excel”);

}

/// <summary>

/// This event is used to export gridview data to word document

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

protected void btnWord_Click(object sender, EventArgs e)

{

ExportFunction(“attachment;filename=GridViewExport.doc”“application/vnd.ms-word”);

}

/// <summary>

/// This Function is used to generate Excel or word document with gridview checkbox selected values

/// </summary>

/// <param name=”header”></param>

/// <param name=”contentType”></param>

private void ExportFunction(string header, string contentType)

{

SaveCheckedValues();

Response.Clear();

Response.Buffer = true;

Response.AddHeader(“content-disposition”, header);

Response.Charset = “”;

Response.ContentType = contentType;

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

gvdetails.AllowPaging = false;

BindGridData();

gvdetails.HeaderRow.Style.Add(“background-color”“#FFFFFF”);

gvdetails.HeaderRow.Cells[0].Visible = false;

for (int i = 0; i < gvdetails.HeaderRow.Cells.Count; i++)

{

gvdetails.HeaderRow.Cells[i].Style.Add(“background-color”“#df5015”);

gvdetails.HeaderRow.Cells[i].Style.Add(“color”“#FFFFFF”);

}

if (ViewState[“CHECKED_ITEMS”] != null)

{

ArrayList CheckBoxArray = (ArrayList)ViewState[“CHECKED_ITEMS”];

int rowIdx = 0;

for (int i = 0; i < gvdetails.Rows.Count; i++)

{

GridViewRow row = gvdetails.Rows[i];

row.Visible = false;

int index = (int)gvdetails.DataKeys[row.RowIndex].Value;

if (CheckBoxArray.Contains(index))

{

row.Visible = true;

row.Cells[0].Visible = false;

}

}

}

gvdetails.RenderControl(hw);

Response.Output.Write(sw.ToString());

Response.End();

}

/// <summary>

///This method is used to populate the saved checked status of checkbox values

/// </summary>

private void PopulateCheckedValues()

{

ArrayList userdetails = (ArrayList)ViewState[“CHECKED_ITEMS”];

if (userdetails != null && userdetails.Count > 0)

{

foreach (GridViewRow gvrow in gvdetails.Rows)

{

int index = (int)gvdetails.DataKeys[gvrow.RowIndex].Value;

if (userdetails.Contains(index))

{

CheckBox myCheckBox = (CheckBox)gvrow.FindControl(“chkSelect”);

myCheckBox.Checked = true;

}

}

}

}

/// <summary>

/// This method is used to save the checkedstate of checkbox values

/// </summary>

private void SaveCheckedValues()

{

ArrayList userdetails = new ArrayList();

int index = -1;

foreach (GridViewRow gvrow in gvdetails.Rows)

{

index = (int)gvdetails.DataKeys[gvrow.RowIndex].Value;

bool result = ((CheckBox)gvrow.FindControl(“chkSelect”)).Checked;

// Check in the Session

if (ViewState[“CHECKED_ITEMS”] != null)

userdetails = (ArrayList)ViewState[“CHECKED_ITEMS”];

if (result)

{

if (!userdetails.Contains(index))

userdetails.Add(index);

}

else

userdetails.Remove(index);

}

if (userdetails != null && userdetails.Count > 0)

ViewState[“CHECKED_ITEMS”] = userdetails;

}

VB.NET Code

Imports System.Collections

Imports System.Data

Imports System.Data.SqlClient

Imports System.IO

Imports System.Web.UI

Imports System.Web.UI.WebControls

Partial Public Class VBExportData

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs)

If Not IsPostBack Then

BindGridData()

End If

End Sub

”’ <summary>

”’ This Method is used to bind gridview

”’ </summary>

Private Sub BindGridData()

Dim con As New SqlConnection(“Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB”)

Dim cmd As New SqlCommand(“select * from UserInformation”, con)

Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

da.Fill(ds)

gvdetails.DataSource = ds

gvdetails.DataBind()

End Sub

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)

‘Verifies that the control is rendered

End Sub

Protected Sub gvdetails_PageIndexChanging(ByVal sender As Object

ByVal e As GridViewPageEventArgs)

SaveCheckedValues()

gvdetails.PageIndex = e.NewPageIndex

BindGridData()

PopulateCheckedValues()

End Sub

”’ <summary>

”’ This event is used to export gridview data to Excel document

”’ </summary>

”’ <param name=”sender”></param>

”’ <param name=”e”></param>

Protected Sub btnExportExcel_Click(ByVal sender As ObjectByVal e 

AsSystem.Web.UI.ImageClickEventArgs) Handles btnExcel.Click

ExportFunction(“attachment;filename=GridViewExport.xls”“application/vnd.ms-excel”)

End Sub

”’ <summary>

”’ This event is used to export gridview data to word document

”’ </summary>

”’ <param name=”sender”></param>

”’ <param name=”e”></param>

Protected Sub btnWord_Click(ByVal sender As ObjectByVal e As 

System.Web.UI.ImageClickEventArgs)Handles btnWord.Click

ExportFunction(“attachment;filename=GridViewExport.doc”“application/vnd.ms-word”)

End Sub

”’ <summary>

”’ This Function is used to generate Excel or word document with gridview checkbox selected values

”’ </summary>

”’ <param name=”header”></param>

”’ <param name=”contentType”></param>

Private Sub ExportFunction(ByVal header As StringByVal contentType As String)

SaveCheckedValues()

Response.Clear()

Response.Buffer = True

Response.AddHeader(“content-disposition”, header)

Response.Charset = “”

Response.ContentType = contentType

Dim sw As New StringWriter()

Dim hw As New HtmlTextWriter(sw)

gvdetails.AllowPaging = False

BindGridData()

gvdetails.HeaderRow.Style.Add(“background-color”“#FFFFFF”)

gvdetails.HeaderRow.Cells(0).Visible = False

For As Integer = 0 To gvdetails.HeaderRow.Cells.Count – 1

gvdetails.HeaderRow.Cells(i).Style.Add(“background-color”“#df5015”)

gvdetails.HeaderRow.Cells(i).Style.Add(“color”“#FFFFFF”)

Next

If ViewState(“CHECKED_ITEMS”IsNot Nothing Then

Dim CheckBoxArray As ArrayList = DirectCast(ViewState(“CHECKED_ITEMS”), ArrayList)

Dim rowIdx As Integer = 0

For As Integer = 0 To gvdetails.Rows.Count – 1

Dim row As GridViewRow = gvdetails.Rows(i)

row.Visible = False

Dim index As Integer = CInt(gvdetails.DataKeys(row.RowIndex).Value)

If CheckBoxArray.Contains(index) Then

row.Visible = True

row.Cells(0).Visible = False

End If

Next

End If

gvdetails.RenderControl(hw)

Response.Output.Write(sw.ToString())

Response.[End]()

End Sub

”’ <summary>

”’This method is used to populate the saved checked status of checkbox values

”’ </summary>

Private Sub PopulateCheckedValues()

Dim userdetails As ArrayList = DirectCast(ViewState(“CHECKED_ITEMS”), ArrayList)

If userdetails IsNot Nothing AndAlso userdetails.Count > 0 Then

For Each gvrow As GridViewRow In gvdetails.Rows

Dim index As Integer = CInt(gvdetails.DataKeys(gvrow.RowIndex).Value)

If userdetails.Contains(index) Then

Dim myCheckBox As CheckBox = DirectCast(gvrow.FindControl(“chkSelect”), CheckBox)

myCheckBox.Checked = True

End If

Next

End If

End Sub

”’ <summary>

”’ This method is used to save the checkedstate of checkbox values

”’ </summary>

Private Sub SaveCheckedValues()

Dim userdetails As New ArrayList()

Dim index As Integer = -1

For Each gvrow As GridViewRow In gvdetails.Rows

index = CInt(gvdetails.DataKeys(gvrow.RowIndex).Value)

Dim result As Boolean = DirectCast(gvrow.FindControl(“chkSelect”), CheckBox).Checked

‘ Check in the Session

If ViewState(“CHECKED_ITEMS”IsNot Nothing Then

userdetails = DirectCast(ViewState(“CHECKED_ITEMS”), ArrayList)

End If

If result Then

If Not userdetails.Contains(index) Then

userdetails.Add(index)

End If

Else

userdetails.Remove(index)

End If

Next

If userdetails IsNot Nothing AndAlso userdetails.Count > 0 Then

ViewState(“CHECKED_ITEMS”) = userdetails

End If

End Sub

End Class

After that run your application output would be like this

If you observe above code I written code to export selected rows of gridview based on checkbox selection.  here I used “maintain state of checkboxes in while paging in gridview” concept to maintain the state of checkboxes while paging in gridview and I added one function that is VerifyRenderingInServerForm this function is used to avoid the error like “control must be placed in inside of form tag”.

If we set VerifyRenderingInServerForm function then compiler will think that controls rendered before exporting and our functionality will work perfectly. Here I used simple code to export gridview data to excel document and for word document we can use the same code (Export to Word) to import gridview data just by replacing GridViewExport.xls to GridViewExport.doc and application/ms-excel toapplication/ms-word

Demo

Now select checkboxes and click on Excel button you will get output like this

Demo for Excel document

Demo for Word document

Download : sample code attached

Now if you’re getting any error message please feel free to let me know ?

Exporting grid data to PDF using asp.net

Introduction:
Here I will explain how to export gridview data to PDF using asp.net.

Description:

In my previous articles I explained clearly “Exporting grid data to Excel and word”. Now I will explain how to export gridview data to PDF using asp.net. In asp.net we don’t have direct feature to export gridview data to PDF for that reason here I am using third party library ITextSharp reference. The dll is available here ITextSharp first download dll from this site after that create one new website in visual studio and add ITextsharp dll reference to newly created website after that design aspx page like this

 <html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head id=”Head1″ runat=”server”>

<title></title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<table>

<tr>

<td align=”right”>

<asp:ImageButton ID=”btnPDF” runat=”server” ImageUrl=”~/PDF.jpg” Width=”32px”

Height=”32px” onclick=”btnPDF_Click”/>

</td>

</tr>

<tr>

<td>

<asp:GridView runat=”server” ID=”gvdetails” DataSourceID=”dsdetails”  

AllowPaging=”true” AllowSorting=”true” AutoGenerateColumns=”false”>

<RowStyle BackColor=”#EFF3FB” />

<FooterStyle BackColor=”#507CD1″ Font-Bold=”True” ForeColor=”White” />

<PagerStyle BackColor=”#2461BF” ForeColor=”White” HorizontalAlign=”Center” />

<HeaderStyle BackColor=”#507CD1″ Font-Bold=”True” ForeColor=”White” />

<AlternatingRowStyle BackColor=”White” />

<Columns>

<asp:BoundField DataField=”UserId” HeaderText=”UserId” />

<asp:BoundField DataField=”UserName” HeaderText=”UserName” />

<asp:BoundField DataField=”LastName” HeaderText=”LastName” />

<asp:BoundField DataField=”Location” HeaderText=”Location” />

</Columns>

</asp:GridView>

</td>

</tr>

</table>

<asp:SqlDataSource ID=”dsdetails” runat=”server”ConnectionString=”<%$ConnectionStrings:dbconnection %>

SelectCommand=”select * from UserInformation”/>

</div>

</form>

</body>

</html>

Here don’t forgot to set the connection string in web.config file here I am getting database connection from web.config file for that reason you need to set the connectionstring in web.config file like this 

<connectionStrings>

<add name=dbconnection connectionString=Data Source=SD;Integrated Security=true;Initial Catalog=MySampleDB/>

</connectionStrings>

After set the connection string in web.config file now we are able to get the data from database and we can bind that data to gridview by using sqldatasource. Now if you run application gridview appears like this

Now in code behind add these references

using iTextSharp.text;

using iTextSharp.text.pdf;

using iTextSharp.text.html.simpleparser;

After that write the following code in code behind


public override void VerifyRenderingInServerForm(Control control)

{

/* Verifies that the control is rendered */

}

protected void btnPDF_Click(object sender, ImageClickEventArgs e)

{

Response.ContentType = “application/pdf”;

Response.AddHeader(“content-disposition”“attachment;filename=UserDetails.pdf”);

Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

gvdetails.AllowPaging = false;

gvdetails.DataBind();

gvdetails.RenderControl(hw);

gvdetails.HeaderRow.Style.Add(“width”“15%”);

gvdetails.HeaderRow.Style.Add(“font-size”“10px”);

gvdetails.Style.Add(“text-decoration”“none”);

gvdetails.Style.Add(“font-family”“Arial, Helvetica, sans-serif;”);

gvdetails.Style.Add(“font-size”“8px”);

StringReader sr = new StringReader(sw.ToString());

Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse(sr);

pdfDoc.Close();

Response.Write(pdfDoc);

Response.End();

}

Demo for PDF document

If you observe above code I added one function that is VerifyRenderingInServerForm this function is used to avoid the error like “control must be placed in inside of form tag”. If we setVerifyRenderingInServerForm function then compiler will think that controls rendered before exporting and our functionality will work perfectly

Download : sample code attached
Now if you’re getting any error message please feel free to let me know ?

Exporting grid data to Word and Excel using asp.net

Introduction: 
Here I will explain how to export gridviewdata to Word and Excel using asp.net.

Description:

I have one gridview that has filled with user details now I need to export gridview data to word or excel document based on selection. To implement this functionality first we need to design aspx page like this

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head id=”Head1″ runat=”server”>

<title></title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<table>

<tr>

<td align=”right”>

<asp:ImageButton ID=”btnExcel” runat=”server” 

ImageUrl=”~/ExcelImage.jpg”

onclick=”btnExcel_Click” />

<asp:ImageButton ID=”btnWord” runat=”server” 

ImageUrl=”~/WordImage.jpg”

onclick=”btnWord_Click” />

</td>

</tr>

<tr>

<td>

<asp:GridView runat=”server” ID=”gvdetails” DataSourceID=”dsdetails”  

AllowPaging=”true”AllowSorting=”true” AutoGenerateColumns=”false”>

<RowStyle BackColor=”#EFF3FB” />

<FooterStyle BackColor=”#507CD1″ Font-Bold=”True” 

ForeColor=”White” />

<PagerStyle BackColor=”#2461BF” ForeColor=”White” 

HorizontalAlign=”Center” />

<HeaderStyle BackColor=”#507CD1″ Font-Bold=”True” 

ForeColor=”White” />

<AlternatingRowStyle BackColor=”White” />

<Columns>

<asp:BoundField DataField=”UserId” HeaderText=”UserId” />

<asp:BoundField DataField=”UserName” HeaderText=”UserName” />

<asp:BoundField DataField=”LastName” HeaderText=”LastName” />

<asp:BoundField DataField=”Location” HeaderText=”Location” />

</Columns>

</asp:GridView>

</td>

</tr>

</table>

<asp:SqlDataSource ID=”dsdetails” runat=”server”ConnectionString=”<%$ConnectionStrings:dbconnection %>

SelectCommand=”select * from UserInformation”/>

</div>

</form>

</body>

</html>

Here don’t forgot to set the connection string in web.config file here I am getting database connection from web.config file for that reason you need to set the connectionstring in web.config file like this 

<connectionStrings>

<add name=dbconnection connectionString=Data Source=SD;Integrated Security=true;Initial Catalog=MySampleDB/>

</connectionStrings>

After set the connection string in web.config file now we are able to get the data from database and we can bind that data to gridview by using sqldatasource. Now if you run application gridview appears like this

 

Now in code behind add this reference

using System.IO;

After that write the following code in code behind


public override void VerifyRenderingInServerForm(Control control)

{

/* Verifies that the control is rendered */

}

/// <summary>

/// This event is used to export gridview data to word document

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

protected void btnWord_Click(object sender, ImageClickEventArgs e)

{

gvdetails.AllowPaging = false;

gvdetails.DataBind();

Response.ClearContent();

Response.AddHeader(“content-disposition”string.Format(“attachment; filename={0}”,“Customers.doc”));

Response.Charset = “”;

Response.ContentType = “application/ms-word”;

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

gvdetails.RenderControl(htw);

Response.Write(sw.ToString());

Response.End();

}

/// <summary>

/// This Event is used to export gridview data to Excel

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

protected void btnExcel_Click(object sender, ImageClickEventArgs e)

{

Response.ClearContent();

Response.Buffer = true;

Response.AddHeader(“content-disposition”string.Format(“attachment; filename={0}”“Customers.xls”));

Response.ContentType = “application/ms-excel”;

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

gvdetails.AllowPaging = false;

gvdetails.DataBind();

//Change the Header Row back to white color

gvdetails.HeaderRow.Style.Add(“background-color”“#FFFFFF”);

//Applying stlye to gridview header cells

for (int i = 0; i < gvdetails.HeaderRow.Cells.Count; i++)

{

gvdetails.HeaderRow.Cells[i].Style.Add(“background-color”“#507CD1”);

}

int j = 1;

//This loop is used to apply stlye to cells based on particular row

foreach (GridViewRow gvrow in gvdetails.Rows)

{

gvrow.BackColor = Color.White;

if (j <= gvdetails.Rows.Count)

{

if (j % 2 != 0)

{

for (int k = 0; k < gvrow.Cells.Count; k++)

{

gvrow.Cells[k].Style.Add(“background-color”“#EFF3FB”);

}

}

}

j++;

}

gvdetails.RenderControl(htw);

Response.Write(sw.ToString());

Response.End();

}

Demo for Word document

 

If you observe above code I added one function that is VerifyRenderingInServerForm this function is used to avoid the error like “control must be placed in inside of form tag”. If we setVerifyRenderingInServerForm function then compiler will think that controls rendered before exporting and our functionality will work perfectly.

Here I used basic code to export gridview data to word document and for excel code is different but we can use the same code (Export to Word) for excel also to import gridview data just by replacingCustomers.doc to Customers.xls and application/ms-word to application/ms-excel but here we have problem that is row background color is applied throughout excel for that reason I made some small code modification and applied color only to the particular columns based on rows.

Demo for Excel document

 

Download : sample code attached

Now if you’re getting any error message please feel free to let me know ?

Debugging : How To Configure IIS 7.0 and Tomcat on Windows Server 2008

Question/Problem : How To Configure IIS 7.0 and Tomcat on Windows Server 2008
I have a Website designed in ASP.NET 3.0 and have another application in Java and after i read your some of the bogs came to know about the dependencies of java and dotnet so decided to combine both of the application in a single one web application. Actually Website in ASP.net is a Bio Portal and the application in java is a webmail Portal. since both are right at there places but the problem is that java based webmail needs Apache tomcat for execution as a must and have installed Bio Portal on a domain hosted on IIS 7.0 (Windows server 2008). is unable to interrelate both the technologies into one. could any one can help me.

Solution : For the purposes of this installation guide I used Java Runtime Version 6 Update 21, Apache Tomcat 6.0.29 and the Microsoft IIS Application Request Routing (ARR) 2.0 module.

You can download the software that I used in this guide from the following locations :

1. Java JRE Version 6 Update 21 (If have installed this go to point 2)
http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. Apache Tomcat (32-bit/64-bit Windows Service Installer) (If have installed this go to point 3)
http://tomcat.apache.org/download-60.cgi

3. IIS Application Request Routing (ARR) 2.0 (If have installed Proceed from here to next)
http://www.iis.net/download/applicationrequestrouting

Start by installing the Java runtime (JRE) and accept the license agreement.

Then change the installation target folder to C:\Java and then click OK and wait while Java installs

Once you have installed Java you can start installing Tomcat. Double-click the apache-tomcat-6.0.29.exe file to invoke the Apache Tomcat Setup Wizard.

Choose a Custom installation and ensure that the Examples are selected as shown here. You wouldn’t necessarily want to install the sample applications in a production environment but we will be using them in this walkthrough so we need to install them.

Select to install Tomcat in the C:\Tomcat folder as shown here and then click Next.

Leave the default HTTP/1.1 Connector port set to 8080 and choose a password for the admin account.

The setup wizard should find your Java installation automatically.

Click install and wait while Tomcat setup completes. When the installation is complete click Finish.

Now that you have Tomcat up and running you can test your installation by pointing your server’s browser at http://localhost:8080 and you should see the default Apache Tomcat welcome page as shown here.

Now that we have got Tomcat working

Now the configuration of IIS 7.0 and Tomcat can be done with two ways

  1. using IIS ARR Module
  2. Using JK 1.2 ConnectorWe will be proceding for the solution step by step, so let us start our first step using IIS ARR Module.

1. How To Configure IIS 7.0 and Tomcat with the IIS ARR Module

we need to install and configure the IIS Application Request Routing module which will allow IIS to act as a proxy server and forward requests on to Tomcat. Run the ARRv2_setup_x86_en-us.EXE file (or ARRv2_setup_amd64_en-us.EXE if you are using 64-bit Windows) to begin the ARR setup routine.

When the ARR module installation has completed it will create a log file (arr_setup.log) which can be found the %TEMP% folder.

Now that the Application Request Routing (ARR) module has been installed we need to configure it to act as a proxy server (this functionality isn’t enabled by default). In IIS Manager highlight the Application Request Routing Cache feature and click Open Feature in the Actions pane.

Click Server Proxy Settings in the Actions pane.

Tick the Enable proxy checkbox and then click Apply. Leave all the default values in place.

Next we need to configure a URL Rewrite rule so that IIS knows what to do with requests which we want to forward to Tomcat. Click the Default Web Site, highlight the URL Rewrite icon and then click Open Feature in the Actions pane.

In the URL Rewrite feature click Add Rules in the Actions Pane.

In the Add Rule(s) dialog box select Blank rule and click OK.

In the Edit Inbound Rule feature assign a name to the new rule and type (examples.+) in the Pattern dialog box. The new rule should default to using Regular Expressions (if it doesn’t ensure that you select this option)

In the Action section of the Edit Inbound Rule feature ensure that the Action type is set to Rewrite and then enter http://localhost:8080/{R:0} in the Rewrite URL dialog box as shown below. Click Apply to create the new rule.

Everything we need to configure is now in place and we are ready to test. Start by browsing the ‘Request Headers’ sample application from Tomcat directly on port 8080 with the result shown here.

The final step is to browse the same ‘Request Headers’ sample application on port 80 so that the request will be handled by IIS before being forwarded to Tomcat by the ARR proxy. If everything is configured correctly you should see the sample application load successfully as shown here.

If you now examine the IIS log file (which can be found in C:\inetpub\logs\LogFiles by default) you will see that the request for the Tomcat sample application was processed by IIS and proxied by the ARR module. The IIS log file contains both the X-ARR-CACHE-HIT and X-ARR-LOG-ID details as shown here.

Using the IIS ARR module means that there is no longer any need to use the Tomcat JK 1.2 ISAPI Connector. However, I would always recommend that you test your application rigorously before deploying it in a production environment. If you do find any issues with ARR you can always get support in the IIS ARR forums here :

http://forums.iis.net/1154.aspx

2. How To Configure IIS 7.0 and Tomcat with JK 1.2 Connector

Now we need to configure the JK 1.2 Connector which will allow IIS to effectively act as a proxy and forward requests on to Tomcat. Start by creating a folder called ‘ISAPI’ under the Tomcat root folder. Then copy the isapi_redirect-1.2.28.dll file into the ‘ISAPI’ folder and rename the file to isapi_redirect.dll as shown here.

In order to configure the Tomcat connector you need to either add an entry in the Windows registry or you can use the isapi_redirect.properties file. The isapi_redirect.properties file tells the connector where to find its configuration files and also where the isapi_redirect DLL file is located. If you have used the same directory structure as I have you can configure your isapi_redirect.properties file as shown here.

We also need to either update or create the two Tomcat connector configuration files (workers.properties and uriworkermap.properties) so that the connector knows how to handle the requests it receives. These configuration files are documented on the Tomcat web site here : The Apache Tomcat Connector – Reference Guide
If you have just installed Tomcat with the sample applications then you can copy the sample uriworkermap.properties file shown here. Both config files need to placed in the Tomcat ‘conf’ folder which in this example is C:\Tomcat\conf

You can also copy the sample workers.properties file as shown below and save it to the C:\Tomcat\conf folder.

Now we need to configure IIS. Start by creating a virtual directory and give it an alias of ‘jakarta’ as shown here. Incidentally, you don’t have to call the virtual directory ‘jakarta’ – you can actually give it any name you like, just so long as the name you choose appears in the extension_uri line of your isapi_redirect.properties file.

Next we need to configure the virtual directory to have execute permission. This was a simple tick-box option in IIS 6.0 but in IIS 7.0 we need to click on the Jakarta virtual directory and then double-click Handler Mappings.

Within the Handler Mappings feature click Edit Feature Permissions in the Actions Pane.

Click Execute in the Edit Feature Permissions dialog box and click OK.

In the Handler Mappings feature you can now see that calls to ISAPI-dll files are enabled.

The next step is to add an ISAPI filter on the web site. To do this click on the web site and then double-click the ISAPI Filters feature.

In the Actions pane click Add.

In the Add ISAPI Filter dialog box enter a name and the path to the isapi_redirect.dll file and click OK.

The Tomcat ISAPI filter should now appear in the ISAPI Filters list as shown here.

The final step we need to take is to configure the ISAPI and CGI Restrictions feature in IIS 7.0. This is analogous to adding or allowing a Web Service Extension in IIS 6.0. In IIS Manager navigate to the Server Home and then double-click on the ISAPI and CGI Restrictions feature.

In the ISAPI and CGI Restrictions feature click Add on the Actions pane.

In the Add ISAPI or CGI Restriction dialog box enter a name and the path to the isapi_redirect.dll file, tick the Allow extension path to execute option and click OK.

The Tomcat ISAPI extension should now appear in the list with a Restriction status of allowed as shown here.

Everything we need to configure is now in place and we are ready to test. I started by requesting the ‘Hello World’ sample application from Tomcat directly on port 8080 with the result shown here.

The final step is to request the same ‘Hello World’ sample application using port 80 so that the request will be handled by IIS before being forwarded to Tomcat. If everything is configured correctly you should see the sample application load successfully as shown here.

If you now examine the IIS log file (which can be found in C:\inetpub\logs\LogFiles unless you moved it) you will see the request for the sample application being handled by IIS over port 80. One behaviour change that I have noticed is that the actual resource being requested isn’t logged with IIS 7.0 whereas it was in IIS 6.0, although I think this is likely to be a change in the bahviour of the ISAPI filter itself rather than any change in how IIS logs requests.

That’s It. I think it will help all of my visitors to have the solution for their problems. If have any Problems please feel free to post comments right here.

%d bloggers like this: