Working with the In Memory File—Saving it to a Database

The HttpInputFile's InputStream property makes saving binary data to a database very simple because it exposes a stream object pointer to the uploaded file automatically. All you must do is use a Stream to read the bytes from the uploaded file, put them into a local byte array, and save it to the database. A Stream object simply provides a way to read and write bytes to and from a source object, which in this case is an image.

Even though you might have a table that already exists in the Northwind database with a field of the Image type, we are going to create our own table for these examples. The reason is that some older versions of Access and SQL Server don't contain this field in the ...

Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.