Search code examples
asp.netexcelgridviewoledb

Asp.Net importing excel does not work on web server


I need to import my excel file to gridview on web. I use this connection method;

  Dim connectionString As String
    If (Path.GetExtension(fullFileName).Equals(".xls")) Then
        connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=2""", fullFileName)
    ElseIf (Path.GetExtension(fullFileName).Equals(".xlsx")) Then
        connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=2""", fullFileName)
    End If

    Dim connExcel As OleDbConnection
    connExcel = New OleDbConnection(connectionString)
    connExcel.Open()

it works fine when I run it on localhost. However, after I transfer the project via FTP to server, it does not bring the same result. In other words, connection fails.

Edit: I take this error; 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine


Solution

  • You can use EPPlus is .net library that reads and writes Excel 2007/2010 files using the Open Office Xml. I tried this thing and working perfectly on server.