Click here to Skip to main content
15,742,120 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a blob which has excel file content in it. lets say my blob be like "0hsijc02dhsic" which has an excel file content. I will enter the blob in the text field and submit the form...Now my blob should be saved as XLSX file...How Do I implement this in c#?

What I have tried:

I passed the blob as a text field in a form and submitted.
Updated 18-Sep-19 4:08am
Maciej Los 18-Sep-19 7:37am    
I doubt that "0hsijc02dhsic" is the content of excel file...
c#Beginnerrrr 18-Sep-19 9:43am    
I just used that as an example and its really not

I passed the blob as a text field in a form and submitted.

There are two types of Excel files: XLS and XLSX - and neither of then are text based. The first is a proprietary binary format, the latter is a set of Zipped XML files. Trying to cram either form into a string will corrupt the data and render the file useless.

Instead, read the Excel data directly into an array of bytes, and send that to SQL via a parameterized query.
It's the same problem with Image data, and the same solution: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] shows a parameterized solution.
Share this answer
c#Beginnerrrr 18-Sep-19 9:39am    
I cannot read the excel directly. The client will be submitting an excel file with data. This data will be stored as a blob in SQL. I need an application where I will just copy-paste the blob from SQL and see the original data in it. I can still read the blob using stream but the problem here is the data is stored in a different server and I can't access it directly(Just the blob value alone is provided).
OriginalGriff 18-Sep-19 9:58am    
If it's stored in a blob in SQL , then it's already stored as binary data. You can;t just "view the blob as text" and expect to see anything useful - as I said, XLSX files are a collection Zipped files, so you'd have to unpack the Zip, and then look at the data in each file. Even then, you probably won't see much that you recognise or can use: you need to use an Excel reader to "decode" the file / date into a DataTable / DataReader or similar.
Dave Kreskowiak 18-Sep-19 10:31am    
You're not getting an Excel file from a TextBox. That's for sure.

I don't know what you consider an "Excel file", but if you're getting the content from a TextBox, it's no longer an Excel file.

If you want the file, then the user is going to have to upload the file itself, not something pasted into a TextBox.
It's not important what kind of data you are storing in a blob field. It might be a *.pdf, *.xls or an image file, etc. The way you write/read data is still the same. You have to "convert" original data to a stream to be able to save it in the database. You have to "convert" stream (blob) to original data to be able to read it. That's all!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900