Thursday, December 17, 2009

Notifying user before leaving without saving

<script language="JavaScript">

  var needToConfirm = true;


  window.onbeforeunload = confirmExit;

  function confirmExit()


    if (needToConfirm)

      return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";



Monday, December 14, 2009

Some useful links

Ten Must-Have Tools Every Developer Should Download Now

Software Engineering Radio


Birmingham Scholar Ship     


"Twelve Priceless Qualities of Success:
1. The value of time.
2. The success of perseverance.
3. The pleasure of working.
4. The dignity of simplicity.
5. The worth of character.
6. The power of kindness.
7. The influence of example.
8. The obligation of duty.
9. The wisdom of economy.
10. The virtue of patience.
11. The improvement of talent.
12. The joy of originating."
Marshall Field

Monday, November 30, 2009

Thursday, November 26, 2009

The only possible solution to generate pdf under Medium Trust level

It’s been a nightmare if you application work fine at your development end and it’s unable to work under production environment; just due to do ACCESS LEVEL ISSUES.

I have to create pdf.

1.       Microsoft reporting was creating a trust level issue so it was rejected.

2.       Then I opt for itextsharp

Again ran into trust level problem.


Then I download the open source code from the itextsharp website and added

using System.Security;

[assembly: AllowPartiallyTrustedCallers()]   attribute inside AssemblyInfo.cs

Compiled the file and uploaded it to server.


Got a function from internet which I modified according to mine needs


protected void btnExportPDF_Click(object sender, EventArgs e)


        Response.ContentType = "application/pdf";

        Response.AddHeader("content-disposition", "attachment;filename=BranchDataExport1.pdf");



        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);


        // I need to get the data from HTML table so I used it’s rendercontrol.


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

        Document pdfDoc = new Document(PageSize.A4, 50f, 50f, 50f, 50f);

        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);





            //Create a footer that will display page number

            HeaderFooter footer = new HeaderFooter(new Phrase("List -: " + DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString(), new Font(1, 10, 1, Color.BLACK)), false);

            pdfDoc.Footer = footer;

            //Parse Html



        catch (Exception ex)


            //Display parser errors in PDF.

            //Parser errors will also be wisible in Debug.Output window in VS

            Paragraph paragraph = new Paragraph("Error! " + ex.Source + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);


            Chunk text = paragraph.Chunks[0] as Chunk;

            if (text != null)


                text.Font.Color = Color.RED;













And this generate pdf for. Also I ran into different sort of problem which I didn’t mention like

Web.Permission….   That was due to the inclusion of file.

Some pdf page related error etc etc.


This whole took mine so much time, so I want you guys don’t waste time on this issue. BEST OF LUCK


Wednesday, November 25, 2009

Pdf generation and Partial Trust problem

There do exist several issues with trust level when using any dll for pdf creation. I first tried microsoft reporting but it requires full trust. Then I opted for itextSharp but again I run into a problem of full trust. This article really help me out to find a way to make the assembly work under medium trust.


Also You can check the current trust level using this code snipped.


AspNetHostingPermissionLevel GetCurrentTrustLevel()


        foreach (AspNetHostingPermissionLevel trustLevel in

        new AspNetHostingPermissionLevel[] {










                new AspNetHostingPermission(trustLevel).Demand();


            catch (System.Security.SecurityException)




            return trustLevel;


        return AspNetHostingPermissionLevel.None;



Tuesday, November 24, 2009

10 Best Libraries for generating PDF Files

10 Best Libraries for generating PDF Files:-



Sunday, March 29, 2009

Saturday, March 14, 2009

How to Configure NameVirtualHost in XAMPP’s Apache Server

Sunday, March 1, 2009

How to Configure NameVirtualHost in XAMPP’s Apache Server

Updated for XAMPP version 1.6.5

Some time ago, I decided to start phasing out static xhtml in favor of pages using PHP includes. To test these new pages, I used’s wonderful XAMPP (which I really can’t recommend highly enough) to install Apache, MySQL, and PHP (among other things). Once I had my local server running, I put each dev site into its own folder in \htdocs\ and navigated to them by

This setup was functional but far from ideal, as the index pages for these local sites weren’t in what could be considered a root directory, which lead to some tip-toeing around when creating links.

Then I discovered the NameVirtualHost feature in Apache. NameVirtualHost allows the server admin to set up multiple domains/hostnames on a single Apache installation by using VirtualHost containers. In other words, you can run more than one web site on a single machine. This means that each dev site (or domain) can then consider itself to have a root directory. You will be able to access each local site as a subdomain of “localhost” by making a change to the HOSTS file. For example, I access the local dev version of this site at http://ardamis.localhost/.

This works great for all sorts of applications that rely on the site having a discernible root directory, such as WordPress.

Unfortunately, setting up NameVirtualHost can be kind of tricky. If you are having problems configuring your Apache installation to use the NameVirtualHost feature, you’re in good company. Here’s how I managed to get it working:
For XAMPP version 1.6.5

1. Create a folder in drive:\xampp\htdocs\ for each dev site (adjust for your directory structure). For example, if I’m creating a development site for on my d: drive, I’d create a folder at:
2. Edit your HOSTS file (in Windows XP, the HOSTS file is located in C:\WINDOWS\system32\drivers\etc\) to add the following line, where sitename is the name of the folder you created in step 1. sitename.localhost

Add a new line for each dev site folder you create. Don’t change or delete the existing “ localhost” line.

Continuing with the example, I’ve added the line: ardamis.localhost
3. Open your drive:\xampp\apache\conf\extra\httpd-vhosts.conf file and add the following lines to the end of the file, using the appropriate letter in place of drive. Do this step only once. We’ll add code for each dev site’s folder in the next step. (Yes, keep the asterisk.)

NameVirtualHost *:80

DocumentRoot "drive:/xampp/htdocs"
ServerName localhost

My DocumentRoot line would be:
DocumentRoot "d:/xampp/htdocs"
4. Immediately after that, add the following lines, changing sitename to the name of the new dev site’s folder, again using the appropriate letter in place of drive. Repeat this step for every folder you’ve created.

DocumentRoot "drive:/xampp/htdocs/sitename"
ServerName sitename.localhost

My DocumentRoot line would be:
DocumentRoot "d:/xampp/htdocs/ardamis"
My ServerName line would be:
ServerName ardamis.localhost
5. Reboot your computer to be sure it’s using the new HOSTS file (you’ll have to at least restart Apache). You should now be able to access each dev domain by way of:


Wednesday, February 18, 2009

Crystal Report Cache Problem

So, You Don't Want To Cache, Huh?

By Joe Burns

Use these to jump around or read it all...

[IE First]
[Pragma Doesn't Work in IE 5]
[ASP Pages Use This]
[Navigator Next]

I get letters now and again asking how to make it so that when a page is loaded into a browser, that page will not be loaded into the browser's cache. Someone would want to do this for a few different reasons. First, if the page contains information that will be readily updated through a refresh command of some sort, you don't want a page in cache to thwart the process. You want the page to be reloaded from the server each time.

Another big concern is when someone is filling out forms. You really don't want the pages cached because if they are, credit card numbers and addresses and all kinds of stuff can be gathered from the cached page.

When people talk about not caching a page, the talk of this command usually comes up:

The old statement was always, plop that between your head commands and you're good to go. No cache! Well, that's just not the case. There are bugs in both Netscape Navigator (NN) and Internet Explorer (IE).

So, if you're really interested in not caching a page, read on.

IE First

The Pragma statement up above sometimes fails in IE because of the way IE caches files. There is a 64K buffer that must be filled before a page is cached in IE. The problem is that the vast majority of the pages using the Pragma statement put it between the HEAD tags.

The HEAD loads and the Pragma comes into play. The browser gets the go ahead to not cache the page, however there is not yet a page to not cache. How's that for backwards logic? Since the page hasn't filled the 64K buffer, there's no page so the Pragma is ignored. Thus...the page is cached.

The solution is to play to the buffer. If you're really serious about the Pragma working, place another set of HEAD tags at the bottom of the document, before the end HTML tag and re-enter the Pragma. This is a suggestion straight from Microsoft Support. The page would look like this:


Text in the Browser Window

This way the Pragma is pretty sure to be read when the buffer is filled.

Pragma Doesn't Work in IE 5

It was news to me too. In order to assure a non-cache, you'll need to add another meta tag:

That sets an immediate expiration on the file. Thus it dies the moment is it born. Place it on your page in the same manner as above. Since you still have the 64k buffer problem to worry about, I would place it in both HEAD tag sections. Better to be safe than sorry. It should look like this:


Text in the Browser Window

ASP Pages Use This

If you write in ASP and want the same non-cache effect, here's the header information.

<% Response.CacheControl = "no-cache" %>>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>

I didn't read anything about placing it a second time, but better safe than sorry.

Navigator Next

Netscape Navigator recognizes a bug when using the Pragma in secure server situations. The site states that even if the pragma command is used, as long as the browser is never closed, the BACK button will enable someone to see the information entered.

Netscape suggests that people shut down the browser after entering to the screen so that the BACK button doesn't have a history to scroll through.

In addition, Netscape suggests the following JavaScript be used in the BODY tag of all pages that should not be cached:

onLoad="if ('Navigator' == navigator.appName) document.forms[0].reset();"

That's That

All of my readings got into the concept of Pragma in both secure and non-secure settings. I guess there's some reason to it, but I'm a fan of not taking chances. If you want a page to not