ASP.NET 2.0 Resources

Powered by Blogger

Generating PDF files with iTextSharp and ASP.NET 2.0

I have been trying to generate some PDF files from ASP.NET 2.0 application using iTextSharp PDF generator library. I needed to fill predefined PDF templates with data and send them directly to my ASP NET application users. Those templates were created with Adobe Acrobat with value placeholders created as form fields. It's quite easy to fill such PDF templates using iTextSharp and it's much easier as creating whole PDF file from scratch (which is also possible with iTextSharp).

iTextSharp is a port of the iText, a free Java-Pdf library. iText is a library that allows developers to extend the capabilities of their web server applications with dynamic PDF document generation. The latest iTextSharp version (3.1.0) is based on iText 1.4. The tutorials and documentation on iTextSharp homepage are quite out of date but the principles remain the same. iTextSharp 3.1.0 compiles and runs on ASP.NET 2.0 without any major problems.

You will first need the PDF file template for this method. You can easily create the template and form fields with Adobe Acrobat. The next step is quite simple. Read PDF file from disk, create instance of PDFStamper class, fill out the PDF form fields and maybe set some global PDF document properties. Finally flatten the generated PDF file and save it to disk (or stream to client if necessary). Look at the following simplified example for further details.

   1:  string formFile = @".\FormDocument_src.pdf";
   2:  string newFile = @".\FormDocument_out.pdf";
   4:  PdfReader reader = new PdfReader(formFile);
   5:  PdfStamper stamper = new PdfStamper(reader, 
   6:       new FileStream(newFile, FileMode.Create));
   7:  AcroFields fields = stamper.AcroFields;
   9:  // set form fields
  10:  fields.SetField("TextValue", "John Doe");
  11:  fields.SetField("TextValue2", "2 Milky Way, London");
  13:  // set document info
  14:  Hashtable info = new Hashtable(); 
  15:  info["Title"] = "Modified Form"; 
  16:  info["Author"] = "Dolly"; 
  17:  info["Creator"] = "My Web App"; 
  18:  stamper.MoreInfo = info;
  20:  // flatten form fields and close document
  21:  stamper.FormFlattening = true;
  22:  stamper.Close();

The PDF file is opened on line 4 using PDFReader class. On the next line PDFStamper class is instantiated and the output PDF file created. On line 7 the AcroFields are read from stamper which is what's interesting for us. There are some PDF form fields filled at lines 10 and 11. The lines 14 to 18 show how to set global PDF document properties. And finally on the line 21 the PDF file is flattened and output stream closed.

Read more > Posted on: 4/24/2006 07:52:00 PM

Searching for .Net 2.0 Charting Control

I am looking for a good charting component compatible with ASP.NET 2.0. I have been comparing and trying various charting controls lately and maybe some of my findings could by also useful for you. I was looking for some control that supports transparent chart caching, saving to files and would easily integrate to existing Asp Net application.I'm looking for something that's capable of generating 2D charts right now, but 3D support would also be welcome. The control should be easy to use but also fully customizable (sounds like a sci-fi huh?).

I have decided not to include samples of generated graphs, as the post would be too long for a blog. There are direct links to example pages for everywhere it was possible.


.netCHARTING is a charting library with support for dozens of kinds of charts. Latest library version (3.4) fully supports ASP.NET 2.0 and supports 2D and 3D graphics, combo charts, splines, line graphs, stacked bars, horizontal bars, pie charts, financial charts, and many others. This control also contains automatic caching subsystem and is one of my favorites. .netCHARTING gallery

Telerik r.a.d.chart

Telerik's r.a.d.chart is specifically designed for ASP.NET charting and focuses on being an easy-to-use component for business reporting in Web applications. It comes together with full Visual Studio® .NET design-time support. Very nice features of this control is the ability to create image maps to facilitate drill-down charts. Telerik online demos

Xceed Chart for .NET

Xceed Chart comes with support for both Windows forms and Web forms controls to support charting in both environments. It uses OpenGL (3D and 2D) and GDI+ (2D) for fast-rendering charts, fill effects, and smooth chart elements, but it also means very fast, real-time rendering on most systems. This library also fully integrates with Visual Studio.

Dundas Chart for ASP.NET

Dundas Chart for ASP.NET is designed for use in ASP.NET applications and adds some features not found in the Windows Forms version, such as more versatile image support and animated flash charts. Dundas Chart for .NET Version 5.0 was designed specifically for Visual Studio 2005, and is seamlessly integrated into the development environment.

There are also some free .net charting components available. Though they did not meet my requirements, they could be very useful in some other project.


ZedGraph is a set of classes, written in C#, for creating 2D line and bar graphs of arbitrary datasets. The classes provide a high degree of flexibility -- almost every aspect of the graph can be user-modified. At the same time, usage of the classes is kept simple by providing default values for all of the graph attributes. The classes include code for choosing appropriate scale ranges and step sizes based on the range of data values being plotted. ZedGraph is maintained as an open-source, is fully compatible with Microsoft .NET Framework 2.0 and looks very professional. ZedGraph also provider webcontrol interface, so it could easily be used from ASP.NET 2.0 applications. ZedGraph charting gallery


NPlot (formerly known as scpl) is a free charting library for .NET. It boasts an elegant and flexible API. NPlot includes controls for Windows.Forms, ASP.NET and a class for creating Bitmaps. Library is accompanied by source code and is released under a BSD-style license. It supports chart types like bar charts, line graphs, and combo charts. Nplot chart examples


SasqChart supports Webforms (compiles also on ASP.NET 2.0), Winforms and rendering to a bitmap files. Its Free for all non commercial developers and it's available with full source code. Supported charts include Bar, Line, Area, Stacked Area and 2D Pie. SasqChart charting gallery

Read more > Posted on: 4/18/2006 09:19:00 PM

ASP.NET 2.0 "Atlas" Control Toolkit

The "Atlas" Control Toolkit is a collection of samples and components that makes it easier then ever to build and consume rich client-side “Atlas” controls and extenders. The toolkit provides both ready to go samples and a powerful SDK to simplify the creation and re-use of your own custom controls and extenders.

AJAX which stands for Asynchronous Javascript and XML is a programming approach that adds a layer of abstraction between the browser and the Web Server. This layer, also referred to as the AJAX engine, handles the browser requests on the client side and connects back to the web server asynchronously whenever required. The asynchronous nature of communications allows users to continue interacting with the application while the data is being fetched by the engine, allowing for better user experience. Atlas is a set of client libraries and Web Server Controls and Web Services that allows you to realize advantages of AJAX while significantly reducing its complexity and development and maintenance pains. Please note that Atlas is not just another implementation of AJAX, Atlas is an evolution of ideas that form the core of AJAX style of programming.

The Atlas features are quite outstanding. It ads object-oriented style of programming to JavaScript, such as a type system, data types, namespaces, events etc. Adding Object Orientation to JavaScript allows you to improve the quality, reusability and maintainability of the code. Atlas libraries have capabilities for handling most of the browser compatibility issues so you do not have to write browser specific scripts. Atlas libraries provide capabilities for handling remote procedure calls. The libraries manage the complexity of making asynchronous calls reducing a call to just a few lines of scripting code.

The following controls and extenders are available in the "Atlas" Control Toolkit...


It allows you to easily link drop downs together. Asynchonously populate them without postbacks! Each time the selection of one the DropDownList controls changes, the CascadingDropDown makes a call to a specified web service to retrieve the list of values for the next DropDownList in the set. CascadingDropDown enables a common scenario in which the contents of one list depends on the selection of another list and does so without having to embed the entire data set in the page or transfer it to the client at all.

Collapsible Panel

Allows you to easily add Collapsible sections to your web page. This extender targets any ASP.NET Panel control. The page developer specifies which control(s) on the page should be the open/close controller for the panel, or the panel can be set to automatically expand and/or collapse when the mouse cursor moves in or out of it, respectively.


The DragPanelExtender allows users to easily add "draggability" to their controls. The DragPanelExtender targets any ASP.NET panel, and takes an additional parameter that signifies the control to use as the "drag handle".


ReorderList is an "Atlas" control that implements a bulleted, data-bound list with items that can be reordered interactively. To reorder the items in the list, the user simply drags the item's control bar to its new location. Graphical feedback shows where the item will be placed as it is dragged by the user. The data source is updated after the item is dropped in its new location.

There are also other AJAX controls and extenders available: ConfirmButton, HoverMenu, PopupControl, TextBoxWatermark and ToggleButton. In addition to the controls and extenders already mentioned above, the toolkit also contains helper classes that eliminate many of the steps needed to create "Atlas" controls or extenders so you can quickly produce the code. The toolkit also contains Visual Studio 2005 Templates for Visual Basic and Visual C# users to create their own controls and extenders.

Read more > Posted on: 4/14/2006 08:24:00 PM

Anthem.NET - The Free ASP.NET 2.0 AJAX Framework

There was an article published recently at eggheadcafe about Building an Anthem.NET [AJAX] Autosuggest Textbox. I didn't bought the AJAX idea quite yet, but I was quite interested when reading this arcticle. There is a good overview how AJAX evolved, but the most intersting point for me was in the arcticle mentioned Anthem.NET AJAX framework.

Anthem.NET is a FREE, cross-browser AJAX toolkit for the ASP.NET development environment that works with both ASP.NET 1.1 and 2.0. It was developed by Jason Diamond when he had the great idea to encapsulate all the hard grunt work of making a regular Web Form control use AJAX and package it into new Anthem Controls. These controls behave just like regular Web Form controls, except they have AJAX built into them!

I had once or twice thought it could be useful to implement some AJAX features to my ASP.NET 2.0 Web Application, but I was always discouraged by the complexity of Microsoft's ASP.NET Atlas Framework. Now it seems Anthem.NET could be something I was looking for. You don't have to write any client javascript code and the integration with existing ASP.NET 2.0 web application is quite easy.

Anthem is actually really simple. When you trigger a call back from your page, the XMLHttpRequest object is used to POST back to the page. Jason tried, as much as possible, to emulate what a normal POST request would look like. This means that the request contains the values for all of the form controls on the page including the ASP.NET specific hidden field like __VIEWSTATE. As far as the page on the server is concerned, a normal post back is occuring. The page fires its Init event, transfers state into the controls, fires its Load event, performs validation, etc. He even let it go through its normal rendering process.

After the page on the server does its thing, Jason captures the HTML of all the "Anthem" controls on the page and "return" that to the client which uses innerHTML to update those controls right there in the browser. This is, admittedly, a hack but it works surprisingly well. And, for the most part, you can just pretend you're working with "normal" ASP.NET pages and controls without having to learn a whole new set of APIs.

You can see why it's called AJAX-like framework. Whole form processing is made at server side. The is not discrete server "page" that just takes the essential parameters, does the minimum amount of processing and returns the minimum amount of data as "Fundamentals of AJAX" from Apress suggests. But there is a simple way to control the AJAX postback processing on server with Anthem.Manager.IsCallBack in your Page_load method, and it's enough for me. I can use AJAX features and UI extensions without learning a whole new API just by using old known web forms.

There are more ASP.NET 2.0 AJAX frameworks available some of them comercial, but some of them also free. I'm planning to review some of them and get back to you with details in some feature posts.

Read more > Posted on: 4/09/2006 08:34:00 AM

Visual Studio 2005 Web Application Projects RC1

One of my first posts on this blog was about Visual Studio 2005 and ASP.NET 2.0 Web Application Projects. It's quite usefull feature, as it brings the classic web project back to Visual Studio 2005.

Now, there is updated RC1 version with a lot of added functionality

Also included in this build is support to automatically migrate a VS 2003 Web Application to be a VS 2005 Web Application Project. With the VS 2005 Web Application Project installed, you can now simply do a File->Open File within VS 2005 and select a VS 2003 .sln or project file to kick off a migration wizard that will convert the project to be VS 2005 Web Application Project (no need to open or modify any project file settings manually anymore). This will provide a straight-forward way to migrate a VS 2003 Web Application to VS 2005 without having to-do much work (because this new project type uses the same compile and project semantics as VS 2003 you shouldn’t need to make code changes to get a VS 2003 app building and running in VS 2005 – we’ll be posting a detailed step-by-step tutorial on how to-do this shortly).
  • Event handler generation and wire-up from the WYSIWYG designer
  • F7/Shift-F7 Navigation Support (switch between page views)
  • Add New Item Wizard to add pages based on Master Pages (easily pick master)
  • Richer Publishing Support
  • Connection String and Settings Support in Web.Config
  • Resources and .Resx Resource Editor Support
  • Support for building multi-project applications and sub-web projects
  • .ASPX files no longer locked when debugging
  • Support for root-path based image and stylesheets (/images/foo.jpg)
  • Control Registrations within Web.Config files
  • Web Service Cross-Project Reference Support
  • Section 508 and WCAG Accessibility Checker Support
  • Ability to create an IIS Vroot/Application setting within Project Dialog
  • SQL DataSource Control Support
  • ASP.NET Custom Folder Templates
  • Component Designer Support
  • Support to Drag/Drop User Controls, StyleSheets, Images from Solution Explorer to designer
  • New Web Service Project Template
  • SQL Express Support

Read more > Posted on: 4/09/2006 07:46:00 AM

ASP.NET 2.0 Features: app_offline.htm

There is a simple way to bring down your ASP.NET 2.0 application. The only thing you have to do is to create simple html file called App_offline.htm and deploy it to your ASP.NET 2.0 web application root directory. The rest is handled by ASP.NET runtime internal routines. But there are also some hidden drawbacks, so keep reading.

Just after you deploy this file, ASP.NET 2.0 runtime stops the application and unloads whole application domain. It stops processing new incomming requests and serves your App_offline.htm file insted. Because whole application domain is unloaded all application files and assemblies are now unlocked and you can make any necessary changes. When you are ready, rename or delete App_offline.htm file and the next incomming request will bring the ASP.NET 2.0 web application back online.

The App_offline.htm file is also used internally by Visual Studio 2005 and Visual Web Developer when deploying web sites to server. If something unusual happend during web site publish, there is a possibility this file will remain on the server and the application will not be functional. So be sure always to check your web application after publishing from Visual Studio 2005 and Visual Web Developer.

But there is one thing you should became aware of when using App_offline.htm file to temporarily shut down your ASP.NET 2.0 web application. When this file is present, all requests are served with this file and returned with status code 404 Not Found. I don't understand why ASP.NET team used this status code, because it clearly is not correct in such situation. The web application pages are only temporarily unavailable, but this status code sais they were not found (that they were deleted)!

Search engine spiders would interpret this status code and remove requested page from their search database. The next thing is Internet Explorer does not show contents of App_offline.htm file in it's default configuration, but a generic friendly message associated with the 404 status code. Fortunately there is a workaround for Internet Explorer friendly message. Internet Explorer first looks at the page size and if it's bigger than 512 bytes 404 status code friendly message is not displayed and user is served with your App_offline.htm content.

So be sure to use this method how to maintain ASP.NET 2.0 application wisely and keep the App_offline.htm deployed for as short time as possible. There is a HTTP status code 503 Service Unavailable meant exactly for such situations when the requested resource is temprorarily unavailable, so let's hope this bad behavior will be changed in the future releases of ASP.NET 2.0 framework.

But enough talking, lets look at some example. I have created this simple App_offline.htm file...

    <title>Application unavailable</title>
    The application is down for maintenance. Please try again in a while.
     Add additional content to make this file bigger than 512 bytes...

Just after i deploy this file to my ASP.NET 2.0 Web Application root directory, this message appears for every application page request.

ASP.NET 2.0 App_offline.htm file request

When i rename or delete this file, the application is brought instantly back online.

Read more > Posted on: 4/05/2006 03:59:00 PM

Free AdSense click tracking script updated!

I have updated the AdSense click tracking script. There is now support for advanced click tracking of AdSense blocks in different languages and some other minor improvements. I have collected data about as many languages the Google AdSense uses as I could. The list is not yet complete, but I think all the most used languages are covered. You can download this free adsense tracking script v2 right now.

If you don't know what i am talking about, here is a little background for you. This script allows you to track clicks on Google AdSense advertisements on your websites and report every single click or AdLinks keyword click to online Google Analytics. Google Analytics interface supports more advanced reporting then AdSense itself. This could help you to optimize you AdSense placement, improve your CTR and eCPM and the best part it's all free.

The installation instructions and other information can be found in my previous blog post Tracking AdSense clicks with Google Analytics. The is also whole tutorial how to interpret tracking results with google analytics in one of my posts: Analyzing and Interpreting AdSense results with Google Analytics.

There is a little difference from previous tracking script version. To support additional languages, the script is now saved in utf-8 encoding. Be sure to preserve this encoding when editing this script, otherwise it won't function correctly. It's also a good idea to reference this javascript with correct charset from your web pages (see the following example).


Read more > Posted on: 4/03/2006 06:35:00 PM

Created dolly