Scenario:
This may not be very common scenario but needed some time to store the files in database. Mostly the attachments needs to be stored in a database instead of maintaining as files.
Solution:
This is very easy with the .NET and SQL Sever environment. Let me start from the database side.We need to have the varbinary field in the database table in order to store the file stream. Look at the below image shows about the table structure.
We can go for the coding part, we'll use File upload control to get the file from the user. We need to convert the file stream in file upload control to byte array. This byte array has to be passed to the database as param.
Look at the screenshot of the code used to store the file,
Hope the above screenshot is explanatory about the code used. I would like to show how this parameter has been handled in executing the stored procedure.
Conclusion:
I believe the above code will be used to store the files in database.
Happy .NETting..
No comments:
Post a Comment