Monday, December 13, 2010

Disable the Back button in Browser

You can use either server side solution or client side (javascript solution)

Server side
After logging out use this code,


client side
include the following text in the head portion of each page.


Thursday, December 9, 2010

Query to get All Column names of a table in Sql server



Friday, November 26, 2010

Removing(Deleting) Querystring in code



If u r removing just like this will not work. U will get error states that 'collection is read-only'.


So the solution is, before deleting the querystring u need to write the below code.

In C#,
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);

// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);

// remove

In VB,
Dim isreadonly As PropertyInfo = GetType(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance Or BindingFlags.NonPublic)

' make collection editable
isreadonly.SetValue(Me.Request.QueryString, False, Nothing)

' remove

Now try. It will work. have a great day. Enjoy....

Tuesday, November 2, 2010

Photo Viewer

The index will go here.Slideshow Mode (10 second delay):On / OffPrevious Next

Friday, October 22, 2010

GridView - Export to Excel


Step 1

Paste this code on export button click.

Protected Sub imgExport_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgExport.Click

Response.AddHeader("content-disposition", "attachment;filename=filename.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"

Dim stringWrite As New StringWriter
Dim htmlWrite As New HtmlTextWriter(stringWrite)

grid.AllowSorting = False
grid.AllowPaging = False


grid.AllowSorting = True
grid.AllowPaging = True

End Sub

If u run this code now, you will get error - 'Control 'ctl00_ContentPlaceHolder1_grid' of type 'GridView' must be placed inside a form tag with runat=server'. so, Don't worry. Just follow Step 2.

Step 2

Just copy and paste the below code. Its done.

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)

' Confirms that an HtmlForm control is rendered for the specified ASP.NET
' server control at run time.

End Sub

Tuesday, September 28, 2010

Merging Pdf files in Asp.Net


1. First u need to download 'itextsharp.dll' from the internet.
2. Then add this dll using add reference.
3. Import the below name space.

Imports iTextSharp.text
Imports iTextSharp.text.pdf

4. Use the below function to merge the pdf.

Public Sub Merge()

Private ReadOnly m_documents As List(Of PdfReader)
Dim newDocument As Document = Nothing

//Merge pdf path. All the pdf files will merged here and become one pdf.
ByVal outputStream As Stream
outputStream = New FileStream(pdfMergePath, FileMode.Create)

newDocument = New Document()
Dim pdfWriter__1 As PdfWriter = PdfWriter.GetInstance(newDocument, outputStream)


Dim pdfContentByte__2 As PdfContentByte = pdfWriter__1.DirectContentUnder

// Add all the pdf to merge
m_documents.Add(New PdfReader(pdfPath1))
m_documents.Add(New PdfReader(pdfPath2))
m_documents.Add(New PdfReader(pdfPath2))

For Each doc In m_documents
totalPages += doc.NumberOfPages

Dim currentPage As Integer = 1
For Each pdfReader As PdfReader In m_documents
For page As Integer = 1 To pdfReader.NumberOfPages

Dim importedPage As PdfImportedPage = pdfWriter__1.GetImportedPage(pdfReader, page)
pdfContentByte__2.AddTemplate(importedPage, 0, 0)

m_baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED)
pdfContentByte__2.SetFontAndSize(m_baseFont, 9)
pdfContentByte__2.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, String.Format("{0} of {1}", currentPage, totalPages), 520, 5, 0)

currentPage = currentPage + 1

If newDocument IsNot Nothing Then
End If
End Try

End Sub

Browser display area or view port width & height using Javascript


The below script will help u to get the width and height of the browser view port area.

function fnScreenWidth() {
//for IE
var viewportwidth;
var viewportheight;

// the more standards compliant browsers (mozilla/netscape/opera/IE7) //use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined') {
viewportwidth = window.innerWidth;
viewportheight = window.innerHeight;

// IE6 in standards compliant mode (i.e. with a valid doctype as the //first line in the document)

else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
viewportwidth = document.documentElement.clientWidth;
viewportheight = document.documentElement.clientHeight;

// older versions of IE
else {
viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
viewportheight = document.getElementsByTagName('body')[0].clientHeight;

alert('Your viewport width is ' + viewportwidth + 'x' + viewportheight);


You can call this java script from body tag,

body onload="fnScreenWidth()"

Get Physical Path of Application in ASP.Net



This wil gets the physical drive path of the application directory for the application hosted in the current application domain.

Monday, September 27, 2010

Accessing session in a class file in Asp.Net


The Session property provides programmatic access to the properties and methods of the HttpSessionState class. Because, ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an .aspx page without the fully qualified class reference to HttpContext. For example, you can use just Session("SessionVariable1") to get or set the value of the session state variable SessionVariable1. However, class file will not inherit System.web namespace. So we need access like below,


Password Encoding and Decoding in ASP.Net


Public Function fnBase64Encode(ByVal strPwd As String) As String
Dim byteEncode(strPwd.Length) As Byte
Dim strEncoded As String

byteEncode = System.Text.Encoding.UTF8.GetBytes(strPwd)
strEncoded = Convert.ToBase64String(byteEncode)

Return strEncoded
End Function


Public Function fnBase64Decode(ByVal strPwd As String) As String
Dim encoder As New System.Text.UTF8Encoding()
Dim utf8Decode As System.Text.Decoder
Dim byteDecode() As Byte
Dim intCharCnt As Integer
Dim strDecoded As String

utf8Decode = encoder.GetDecoder()
byteDecode = Convert.FromBase64String(strPwd)
intCharCnt = utf8Decode.GetCharCount(byteDecode, 0, byteDecode.Length)

Dim charDecoded(intCharCnt) As Char

utf8Decode.GetChars(byteDecode, 0, byteDecode.Length, charDecoded, 0)
strDecoded = New String(charDecoded)

Return strDecoded
End Function

The maximum report processing jobs limit configured by your system administrator has been reached.

Possible Causes

The error message appears because the web application has exceeded the Crystal Reports reporting engine default print job limit of 75. Or, in other words, a high reporting load has been placed on the reporting engine. There are a number of reasons why the report engine would suffer from high loads and each reason may have a distinct solution as documented below.

Coding Issues

Proper coding requires that any objects be managed and thus destroyed when they are no longer needed. This is true for any object that supports IDisposable interface.

Too Many Print Jobs Submitted to the Report Engine

Starting in version 10 of Crystal Reports, the reporting engine was optimized for greatest report throughput. There are specific registry keys that control this optimization. By default, the print job limit is set to 75 print jobs. When a load is placed on the application it can hit the 75 print job limit and cause the error. Note that a print job includes main reports, subreports, and in-session report objects (e.g.; drill down, paging, searching, and more.). Therefore a single report could exceed the 75 print job limit. Consider a report that returns 75 records, with a subreport placed in the detail section and thus running for each record. This report will need to run 75 subreports plus the main report, reaching 76 print jobs and the error will be thrown.


First Delete report files in temp folder(C:\Documents and Settings\[UserName]\Local Settings\Temp) with the extension rpt.

1. Dispose un-needed objects on Page_Unload

Ensure that you call .Dispose and .Close method when the report object is no longer need. Also, ensure that this is done not only with Crystal Reports, but FileStream, Database Connections, datasets or any other object that supports IDisposable interface.

Dim cryDoc As ReportDocument

On page Unload dispose the Report Document Object.


This is the Correct Solution.

2. Increase the 75 Print Job Limit

This may stop the error from occurring temporarily but as load increases, you will find the error will start to occur again or worse yet, the system may stop responding and a system reboot will be the only way to recover. For an application using the Crystal reports SDK, the registry key “InprocServer” sets the limit for the number of print jobs allowed to be processed by the report engine.

Note: The default value of 75 is the predetermined value for best performance in tested environments. Changing this value may affect performance of the system.

To change the PrintJobLimit value, follow these steps:

1)Click Start > Run. The Run dialog box appears.
2)Type “regedit” in the Open field. Click OK. The Registry Editor appears.
Navigate to the appropriate registry key value as documented below.

Crystal Reports 10.0.x
HKEY_LOCAL_MACHINE\SOFTWARE\Crystal Decisions\10.0\Report Application Server\ InprocServer\PrintJobLimit

Crystal Reports 10.2 (Visual Studio .NET 2005 bundle)

HKEY_LOCAL_MACHINE\SOFTWARE\Crystal Decisions\10.2\Report Application Server\ InprocServer\PrintJobLimit

Crystal Reports Basic for Visual Studio 2008 (Visual Studio .NET 2008 bundle)
HKEY_LOCAL_MACHINE\SOFTWARE\Business Objects\10.5\report Application server\InProcServer\ PrintJobLimit\PrintJobLimit

Crystal Reports XI Release 1 (11.0.x)
HKEY_LOCAL_MACHINE\SOFTWARE\Business Objects\Suite 11.0\Report Application Server\InprocServer\PrintJobLimit

Crystal Reports XI Release 2 (11.5.x)
HKEY_LOCAL_MACHINE\SOFTWARE\Business Objects\Suite 11.5\Report Application Server\InprocServer\PrintJobLimit

Crystal Reports 2008 (12.x.x)

HKEY_LOCAL_MACHINE\SOFTWARE\Business Objects\Suite 12.0\Report Application Server\InprocServer\PrintJobLimit