Skip to main content


Showing posts from October, 2008

Google Search

Custom Search

Live Search

Yahoo Search

Search the web Search this site

Correcting the error at User Control

Recently I got an error in an user control which I used to create users in Active Directory. This user control started to fail in SharePoint after deploying it in to a different server. It threw the following error,Exception has been thrown by the target of an invocation. The Inner Exception was Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))After a bit of a struggle I found that the error was due to inappropriate setting in Web.Config file.To correct it set identity impersonate to false.<identity impersonate="false" />

Creating an Excel Sheet using .Net

In this entry I will show how you can create a Microsoft Excel file using .Net.
// Create the Excel Application object.
ApplicationClass ExcelApp = new ApplicationClass();
// Set the visibility of the application.
ExcelApp.Visible = true;
// Create a new Excel Workbook.
Workbook ExcelWorkbook = ExcelApp.Workbooks.Add(Type.Missing);
// Create a new Excel Sheet.
Worksheet ExcelSheet = (Worksheet)ExcelWorkbook.Sheets.Add(ExcelWorkbook.Sheets.get_Item(1), Type.Missing, 1, XlSheetType.xlWorksheet);
// Loop for 10 rows.
for (int rwCount = 1; rwCount <= 10; rwCount++) { // Loop for 3 columns. for (int clmCount = 1; clmCount <= 3; clmCount++) { ExcelSheet.Cells[rwCount, clmCount] = "This is Row - " + rwCount + " Column - " + clmCount; } } // Save the Excel sheet. // The @ symbol makes the string to contain any special characters inside the string without breaking th…

Accessing Data in an Excel File using .Net

In this article I will show how you can open Microsoft Excel files using .Net.
You can use OLE objects to access data in Excel files as of you are accessing SQL Server data using SQL objects.

// Create an OLEDBConnection to connect to the Excel file.
// I'm getting the required file by using a file dialog.
// The @ symbol makes the string to contain any special characters inside the string without breaking the string.
OleDbConnection dbConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog1.FileName.ToString()+ @";Extended Properties=""Excel 8.0;HDR=Yes;""");
// Open the connection.
// Create a command object to work on the data.
// Note that I have given the sheet name as [Sheet1$] to retrieve data from that named sheet in the particular Excel file.
OleDbCommand dbCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", dbConnection);
// Creating a data reade…