Hello,
My code works just fine when I run it locally, but when I put it up on a test server and try to import an excel file which resides on my local machine I get this error:
'C:\Documents and Settings\rflint\Desktop\Import Folder\InventoryImportTemplate.xls' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
Here is the Upload function:
Protected Sub ButtonUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ExcelFilePath As String = FileUpload1.PostedFile.FileName
Dim ExcelFileName As String = FileUpload1.FileName
If IsPostBack Then
Try
Dim conn As OleDbConnection = Nothing
Dim excelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ExcelFilePath & ";Extended Properties=Excel 8.0;;Persist Security Info=False"
' Create Connection to Excel Workbook
Using connection As New OleDbConnection(excelConnectionString)
Dim command As New OleDbCommand("Select * from [Sheet1$]", connection)
connection.Open()
' Create DbDataReader to Data Worksheet
Using dr As OleDbDataReader = command.ExecuteReader()
' SQL Server Connection String
Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrin gs(1).ToString)
myConnection.Open()
' Bulk Copy to SQL Server
Using bulkCopy As New SqlBulkCopy(myConnection)
bulkCopy.DestinationTableName = "ExcelData"
bulkCopy.WriteToServer(dr)
End Using
myConnection.Close()
GetExcelData()
End Using
End Using
Catch ex As Exception
Response.Write(ex.Message)
Finally
End Try
End If
End Sub