Free Support Forum - aspose.com

Resolve issue "Cannot find a part of the path" while loading Excel file using Aspose.Cells for .NET in VB .NET

I'm trying to create a proof of concept page using the Aspose Cells API.

The function of the page is to have the user upload an Excel file from their computer, and then have the API take the data from the one worksheet in that file and load it into a DataTable, then to a DataGrid.

I have the code in place to do this, but I keep getting an error saying that part of the path cannot be found. Here is the code that I have:

'Get file name and assign it to the variable
Dim pathName As String
pathName = System.IO.Path.GetFileName(Me.FileUploadReport.PostedFile.FileName)
'pathName = Me.FileUploadReport.PostedFile.FileName.ToString

'Instantiate a new workbook
Dim workbook As New Workbook(pathName)

'Get the first worksheet in the workbook
Dim worksheet As Worksheet = workbook.Worksheets(0)

'Create a datatable
Dim datatable1 As New DataTable()

'Export worksheet data to a datatable object by calling either ExportDataTable or ExportDataTableAsString
'method of the Cells class
datatable1 = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.MaxRow + 1, worksheet.Cells.MaxColumn + 1)

'Bind the DataGrid with DataTable
DataGrid1.DataSource = datatable1
DataGrid1.ShowHeader = True
DataGrid1.DataBind()

Do you have any ideas why it isn't able to find the path?

Hi,


Could you replace the line of code (in your code) i.e.
Dim workbook As New Workbook(pathName)
to:
Dim workbook As Workbook = New Workbook(Me.FileUploadRepport.PostedFile.InputStream)


Thanks

Thanks for getting back to me so soon.

I changed the code like you said, and it looks to be working just fine. Thank you very much.

Hi,


Good to know that your issue is resolved!

Feel free to contact us any time if you need further help or have any issue regarding Aspose.Cells product family, we will be happy to assist you.

Thank you.