November 5th, 2015

Export Data to Excel (.xls, .xlsx) in ASP.NET – C#

In this article, we will see different ways to export data to Excel from a web application. It is very common task for web developers. Here are different approaches to do it in ASP.NETC#:

Approach 1:

Using the Excel PIA (primary interop assemblies) to generate a spreadsheet server-side.

It needs Microsoft Office suite installed on your server which is not good. So it is NOT recommended.

January 19th, 2015

Bulk Insert – Save DataTable to MongoDB – C# MongoDB Driver 2.1

Do you want to import csv or excel (xls, xlsx) file in MongoDB? You can read the file, get the data in C# datatable and save it to MongoDB using InsertBatch method. This article explains how to save C# DataTable to MongoDB for inserting a large amount of data.

To install Official .NET driver for MongoDB, run the following command in the Package Manager Console

Install-Package MongoDB.Driver

January 15th, 2015

Upload and Read Excel File (.xls, .xlsx) in ASP.NET MVC

Are you using traditional way to read .xls and .xlsx files in ASP.NET/C#? If yes, you might be using following providers:
Microsoft.Jet.OLEDB.4.0 provider for Excel 97-2003 format (.xls)
Microsoft.ACE.OLEDB.12.0 provider for Excel 2007+ format (.xlsx)

and you may get the following common errors:

The ‘Microsoft.Jet.OLEDB.4.0’ provider is not registered on the local machine.
The ‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine.

and probably, you would go for following approach to fix them

1. Installation of Office 2007 Data Connectivity Components or Office 2010 Database Engine on the Server.
2. The application pool that the site is running set “Enable 32-bit applications” to “True
3. In project, Change Platform target from: Any CPU to x86 and Rebuild it.

What would happen if you have shared hosting or Azure Website hosting and You are not allowed to install ACE Database engine on the server?

January 17th, 2013

Saving SkyDrive Excel Survey Data To Sql Server Database with ASP.NET MVC

SkyDrive provides the excel survey feature which allows you to create online surveys and analyze results using the free Excel Web App or Excel on your desktop. You can display the survey results by embedding the excel in a web page. allows you show a workbook directly in your website. It also lets you easily sort, filter, and interact with the workbook as in Web Excel with powerful Javascript API. We will create a sample survey and save result data to database using ASP.NET MVC and Entity Framework.

April 12th, 2011

How to Remove Line Numbers in Excel Column

It explains how you can remove line numbers and get proper data in a excel column. Suppose you have data in following format in A column:
1. First Data
2. Second Data
3. Third Data
4. Fourth Data
5. Fifth Data

You have to remove line numbers and get content in another column. See following screen-shot: