How to create a unit test

In order to test the methods you developed, you need to have unit tests. For this purpose you may visit the following URLs explaining 1) How to Create ASP.NET Unit tests 2) Data-Driven Unit tests

Tableless web designing

If you want to make your web page lighter than the normal page size then you must use the tableless web design/tableless formating/ tableless layout. You can find the detailed description on the following URLs:




Error in creating Excel Object : Retrieving the COM class factory

You might have faced a problem while creating an object of MS Excel using


Excel.ApplicationClass xl = new Excel.ApplicationClass();


resulting in the following error.


Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.


Possible reasons for it are that your ASPNET account doesnt have enough permissions to create that COM object so you have to grant permissions to the user which is accessing that COM object.

By default ASP.NET web applications run under the ASPNET account, if you are using impersonation than the <machine_name>IUSR_<machine_name> is used to run that application so in each case you have to grant permissions to the respective users


You can grant permissions to those accounts to access the COM object on Windows XP using the following steps:



Configure DCOM

  • Go to the Start-Run menu item.
  • Type in “DCOMCNFG” and hit enter.
  • This should load the “Component Services” MMC (you can also load from Administrative Tools – Component Services”
  • Expand “Component Services”
  • Expand “Computers”
  • Expand “My Computer”
  • Select the “DCOM Config” item
  • Select the “Microsoft Excel Application” item.
  • Right click and select Properties
  • Select the Security Tab
  • Under “Launch and Activation Permissions” select the “Customize” option.
  • Click the “Edit” button
    • Click the “Add” button to add a new account to the list.
    • On the dialog that is displayed click the Locations button

      (select the first item which is your computer name)



  • Click the OK button
  • On the dialog that is displayed enter “ASPNET” as the account name (make sure location is set to the name of the computer that IIS is on) onWindows XP
  • On the dialog that is displayed enter “IUSR_” as the account name if you are using impersonation (make sure location is set to the name of the computer that IIS is on) onWindows XP



  • Click the OK button
  • Now make sure you select the following options for the “ASP.NET Machine Account” or the account that is the application pool identity ( by default Network Service)

    • Local Launch : Allow
    • Remote Launch : [blank]
    • Local Activation : Allow
    • Remote Activation : [blank]


Click the OK button and test your web application again and it should work fine.

The above steps have been taken from the following URL and you can go through it for a more detailed walk through

Microsoft Office Excel cannot access the file

You might have experienced a problem while opening an excel file using



Excel.Workbook workBook = app.Workbooks.Open(Path, 0, true, 5, “”, “”, true, Excel.XlPlatform.xlWindows, “t”, false, false, 0, true, 1, 0);


and ended up with the following error


Microsoft Office Excel cannot access the file ‘\ExcelFile.xls’. There are several possible reasons:


• The file name or path does not exist.

• The file is being used by another program.

• The workbook you are trying to save has the same name as a currently open workbook.


This problem occurs on IIS 5 and IE 6.


It is a known issue and Microsoft offers a hotfix for IE 6 to overcome this issue.


You can find a detailed description of the problem and the link to download the hotfix on



How to handle RadGrid’s Select Column Checkbox Event


Do these steps to handle the Radgrid’s select column checkbox event.


1. Allow row selection


<ClientSettings …>

<Selecting AllowRowSelect=”true” />




2. Place the select column/row checkbox

<telerik:RadGrid …>

<ClientSettings …>…</ClientSettings>




<telerik:GridClientSelectColumn UniqueName=”Selectcol” HeaderText=”select”>






3. Specify the ItemCreated Event



4. Define ItemCreated Event

protected void  RadGrid_ItemCreated(object sender, GridItemEventArgs e)


GridHeaderItem HeaderItem;

GridDataItem DateItem;

CheckBox chkbx=new CheckBox();

if (e.Item is GridHeaderItem)


HeaderItem = (GridHeaderItem)e.Item;

chkbx = (CheckBox)HeaderItem[“SelectCol”].Controls[0];


if (e.Item is GridDataItem)


DateItem = (GridDataItem)e.Item;

chkbx = (CheckBox)DateItem[“SelectCol”].Controls[0];


chkbx.AutoPostBack = true;

chkbx.CheckedChanged += new EventHandler(chkbx_CheckedChanged);


5. Define chkbx_CheckedChanged


void chkbx_CheckedChanged(object sender, EventArgs e)






How to close jQuery ColorBox on file download

Lets suppose you want to display a custom message in a jquery colorbox before a user can download a file, on clicking an agree button on that colorbox, user should be prompted to download/save/open the file and the colorbox should be closed, use the following steps to do so


1. Agree button event handler on the colorbox page should do this


protected void btnAgree_Click(object sender, EventArgs e)


Session[“FilePath”] = YourCompleteFilePath;//put your complete file path here

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), “popupclose”, “window.location.href=’DownloadFile1.aspx’;parent.$.colorbox.close();”, true);


2. Page load on the DownloadFile1.aspx should have the following code




byte[] FileData = new byte[0];

string filePath = Server.MapPath(Session[“FilePath”].ToString());

FileInfo file = new FileInfo(filePath);

if (file.Exists)//set appropriate headers



Response.AddHeader(“Content-Disposition”, “attachment; filename=” + file.Name);

Response.AddHeader(“Content-Length”, file.Length.ToString());

Response.ContentType = “application/octet-stream”;




Report Viewer: Export to Excel in One Sheet

When you group your report based on some column, and then try to export to excel, it inserts a page break after certain records.

If you want to export complete data in one sheet of excel workbook. Do the followings

1. Right Click on Rdlc file

2. Select Open With

3. Select “XML (Text) Editor”

4. Add this tag <InteractiveHeight>0in</InteractiveHeight> inside <Page> tag

5. Save the file

6. Open the report

7. Remove all other page breaks from the reports

8. Remove the group page break as show in the attached image

9. Remove the report viewer height

Run the report, it will show results in one window as well as it will export the data in a single sheet of excel workbook