File Byte Convert To DataSet

Anumanth B

New member
Joined
Jul 9, 2020
Messages
1
Programming Experience
1-3
Hi friends..

I Have file byte like this byte[] filebyte = FileUpload1.FileBytes;
This byte actually xlsx or xls file byte.
My Achive is the same byte is xls or xlsx file byte i need to convert Dataset otherwise directly use this byte.
Please help me friends..
 
I'm don't understand what you're trying to say. If you want to save the data to a database then you treat it like any other data. How would you save a string? That's the same way you save a byte array.
 
The brute force way:
Save the byte array into a temporary file with the appropriate .XLS or .XLSX extension.
If you are not on a server, then use ACE OLEDB drivers to open a connection the file.
Use usual ADO.NET adapter classes to load a DataSet from a database.
 
The brute force way:
Save the byte array into a temporary file with the appropriate .XLS or .XLSX extension.
If you are not on a server, then use ACE OLEDB drivers to open a connection the file.
Use usual ADO.NET adapter classes to load a DataSet from a database.
Ah, so you're interpreting it as someone is uploading an Excel file and the application needs to read the data from that workbook. That makes sense. In that case, you might consider saving the file like this:
C#:
var filePath = Path.GetTempFileName();

File.WriteAllBytes(filePath, fileData);
That will save the file in the dedicated Temp folder with a random file name and a ".tmp" extension. If you have a dedicated folder and/or file name that you want to use then you can still call File.WriteAllBytes but with a different path.

As far as reading the data, you might have some issues. If you're using a dedicated web server then you will certainly not have Microsoft Office installed, so you would need to install the ACE provider separately. It's unlikely that a hosting service will do that and many/most IT departments probably wouldn't either. If you want to use ADO.NET to read the data, first make sure that you can/do have ACE installed.

The alternative, for XLSX files at least, is to use the OpenXML SDK in your application to read the data. The code will be a bit more complex but the appropriate library(ies) can be deployed as part of your application so you know that the functionality will be available no matter where you app is hosted.

I forgot to mention that you should be able to use the Jet provider to read XLS files but not XLSX. I'm fairly sure that jet is part of all Windows versions including servers, but you might want to confirm that if you want to use it. Also, Jet is 32-bit only, so your application would have to be 32-bit also.
 
Exactly what I told a team that was wondering why their app was broken on our fresh new IIS servers: No go for ACE, but they are welcome to run as 32-bit and use JET if they actually only play with .XLS. If they wanted 64-bit, the OpenXML SDK is there for them to use, or they could find another library that is meant for server use.

The download page for ACE has text specifically saying that it is not for server use.
 
Back
Top Bottom