How to upload a excel’s data into a List or DataTable without saving and then deleting the excel file?
I use asp.net C#.
For example, I have a excel file with some data, and I want to get the data from the excel file into a List or DataTable without saving the excel into a file system and then deleting the excel file. So I can avoid the IO operation.
Its doable, but it depends on the type of Excel file.
If its a CSV, you can use a StreamReader on the response stream to parse the CSV line by line. You can then use the TextFieldParser (don’t be scared by VisualBasic in the namespace!) to parse the CSV from the stream. Here’s a link with some info about the TFP.
If you’re talking about a .xls or an .xlsx, it depends on the libraries you use. Different libraries will do things differently, but most likely they will take a stream that contains the file (whether that stream is a FileStream or a response stream–gotta love polymorphism!) and load it from there.