Code On Time web applications automatically handle storage of binary large objects (BLOB). For example, the Northwind sample database contains pictures of each record in the Categories table. The web app displays the pictures in the grid and form views. Clicking on the thumbnail will download the picture.
Open the edit form for a category and edit the record. The control under the Picture thumbnail allows replacing or clearing the blob stored in the field.
Any type of file may be uploaded to the field. However, the file name and type is not stored by the database. When the user tries to download the file again, the user will receive a message similar to the one below.
The generic file name is “CategoriesPicture_1” and the content type is “.octet-stream”.
In order to preserve the file name and type, utility fields will be added to the Categories table.
Start SQL Server Management Studio. In the Object Explorer, right-click on Databases / Northwind / Categories and press Design.
Add the following columns:
|Column Name||Data Type||Allow Nulls|
Please note that these columns are case-sensitive. If the name of your field is “XXX”, the application framework will attempt to locate utility fields “XXXFileName”, “XXXContentType”, and “XXXLength”.
Save the changes to the table.
Start the web application generator. Click on the project name and press Refresh. Select Categories controller and continue to refresh the project.
Continue to regenerate the web app. When complete, navigate to the Categories page. Select a record, and upload any non-image file.
Note that the three utility fields have automatically been updated. Click on the thumbnail to download the file. Note that the file name and type have been correctly added.