I want to implement upload (.xls/.xlsx/.csv) file.
But I don't want to use any thing which needs to be installed in the server. If I implement Upload functionality in my local code same should work after deployment without installing anything in the server. I am using .NET frame work 2.0. Its old application.
Yes Path I can provide App_Data. I don't want to insert data to DB. Just I want to upload then put it in DataTable.Then I will bind that DataTable to Repeater Control for display.
I tried below code but for this we requre installation in the server(as I mentioned I don't want to install anything in the server):
The JET provider should be available as part of the Windows operating system. The ACE provider needs to be installed separately. If you cannot install the ACE provider, you will have to ask users to save their Excel files as Excel 97-2003 Workbook (.xls)
for your application to be able to read the data.
If, for some reason, the JET provider is not available on your server either, then you simply will not be able to work with Excel files at all. You will have to ask your users to upload files in some text-based format such as CSV or tab delimited etc.
Do you have sample code for read excel file(xls/xlsx) / csv and upload without using anyother component that means without installing anything in the server like JET provide, ACE provider etc. We don't know what is the server configuration. In our local
machine it works same thing should work after deploying.
Do you have sample code for read excel file(xls/xlsx) / csv and upload without using anyother component that means without installing anything in the server like JET provide, ACE provider etc
No, I do not have such code. For your requirement, it is best either to know server configuration., either to buy a custom component/.
Protected Sub ButtonUploadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonUploadFile.Click
If FileUploadExcel.HasFile Then
Try
' alter path for your project
FileUploadExcel.SaveAs(Server.MapPath("~/DataBasefolder/ExcelImport.xls"))
LabelUpload.Text = "Upload File Name: " & _
FileUploadExcel.PostedFile.FileName & "<br>" & _
"Type: " & _
FileUploadExcel.PostedFile.ContentType & _
" File Size: " & _
FileUploadExcel.PostedFile.ContentLength & " kb<br>"
Catch ex As Exception
LabelUpload.Text = "Error: " & ex.Message.ToString
End Try
Else
LabelUpload.Text = "Please select a file to upload."
End If
End Sub
Protected Sub ButtonView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonView.Click
If File.Exists(MapPath("~/DataBasefolder/ExcelImport.xls")) Then
LabelStatus.Text = "" ' reset to blank
Dim strExcelConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("~/DataBasefolder/ExcelImport.xls") & ";" & _
"Extended Properties='Excel 8.0;HDR=Yes'"
Dim connExcel As New OleDbConnection(strExcelConn)
Dim cmdExcel As New OleDbCommand()
cmdExcel.Connection = connExcel
connExcel.Open()
Dim dtExcelSchema As DataTable
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
connExcel.Close()
Dim ds As New DataSet()
cmdExcel.CommandText = "SELECT * FROM [Sheet1$]"
Dim da As New OleDbDataAdapter()
da.SelectCommand = cmdExcel
da.Fill(ds)
GridViewExcel.DataSource = ds.Tables(0).DefaultView
GridViewExcel.DataBind()
Else
LabelStatus.Text = "XLS File does not exist"
End If
End Sub
santoshhegde
Member
10 Points
25 Posts
upload (.xls/.xlsx/.csv) file without installing anything in the server
Jan 31, 2013 05:05 AM|LINK
Hi,
I want to implement upload (.xls/.xlsx/.csv) file.
But I don't want to use any thing which needs to be installed in the server. If I implement Upload functionality in my local code same should work after deployment without installing anything in the server. I am using .NET frame work 2.0. Its old application.
Please give me a sample code to achive this.
ignatandrei
All-Star
134960 Points
21632 Posts
Moderator
MVP
Re: upload (.xls/.xlsx/.csv) file without installing anything in the server
Jan 31, 2013 05:44 AM|LINK
for uploading you need somewhere to upload to ( a database, a path on server)
Then you can upload any kind of file
To read data from files it is another story
santoshhegde
Member
10 Points
25 Posts
Re: upload (.xls/.xlsx/.csv) file without installing anything in the server
Jan 31, 2013 05:49 AM|LINK
Hi,
Yes Path I can provide App_Data. I don't want to insert data to DB. Just I want to upload then put it in DataTable.Then I will bind that DataTable to Repeater Control for display.
I tried below code but for this we requre installation in the server(as I mentioned I don't want to install anything in the server):
if (fileExtension == ".xls"){
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}else if (fileExtension == ".xlsx"){
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
Mikesdotnett...
All-Star
154897 Points
19862 Posts
Moderator
MVP
Re: upload (.xls/.xlsx/.csv) file without installing anything in the server
Jan 31, 2013 07:01 AM|LINK
The JET provider should be available as part of the Windows operating system. The ACE provider needs to be installed separately. If you cannot install the ACE provider, you will have to ask users to save their Excel files as Excel 97-2003 Workbook (.xls) for your application to be able to read the data.
If, for some reason, the JET provider is not available on your server either, then you simply will not be able to work with Excel files at all. You will have to ask your users to upload files in some text-based format such as CSV or tab delimited etc.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
santoshhegde
Member
10 Points
25 Posts
Re: upload (.xls/.xlsx/.csv) file without installing anything in the server
Jan 31, 2013 08:18 AM|LINK
Hi ignatandrei,
Do you have sample code for read excel file(xls/xlsx) / csv and upload without using anyother component that means without installing anything in the server like JET provide, ACE provider etc. We don't know what is the server configuration. In our local machine it works same thing should work after deploying.
ignatandrei
All-Star
134960 Points
21632 Posts
Moderator
MVP
Re: upload (.xls/.xlsx/.csv) file without installing anything in the server
Jan 31, 2013 08:26 AM|LINK
No, I do not have such code. For your requirement, it is best either to know server configuration., either to buy a custom component/.
doublehaul
Member
15 Points
8 Posts
Re: upload (.xls/.xlsx/.csv) file without installing anything in the server
Feb 01, 2013 07:40 PM|LINK
Protected Sub ButtonUploadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonUploadFile.Click If FileUploadExcel.HasFile Then Try ' alter path for your project FileUploadExcel.SaveAs(Server.MapPath("~/DataBasefolder/ExcelImport.xls")) LabelUpload.Text = "Upload File Name: " & _ FileUploadExcel.PostedFile.FileName & "<br>" & _ "Type: " & _ FileUploadExcel.PostedFile.ContentType & _ " File Size: " & _ FileUploadExcel.PostedFile.ContentLength & " kb<br>" Catch ex As Exception LabelUpload.Text = "Error: " & ex.Message.ToString End Try Else LabelUpload.Text = "Please select a file to upload." End If End Sub Protected Sub ButtonView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonView.Click If File.Exists(MapPath("~/DataBasefolder/ExcelImport.xls")) Then LabelStatus.Text = "" ' reset to blank Dim strExcelConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("~/DataBasefolder/ExcelImport.xls") & ";" & _ "Extended Properties='Excel 8.0;HDR=Yes'" Dim connExcel As New OleDbConnection(strExcelConn) Dim cmdExcel As New OleDbCommand() cmdExcel.Connection = connExcel connExcel.Open() Dim dtExcelSchema As DataTable dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) connExcel.Close() Dim ds As New DataSet() cmdExcel.CommandText = "SELECT * FROM [Sheet1$]" Dim da As New OleDbDataAdapter() da.SelectCommand = cmdExcel da.Fill(ds) GridViewExcel.DataSource = ds.Tables(0).DefaultView GridViewExcel.DataBind() Else LabelStatus.Text = "XLS File does not exist" End If End Sub