This is a migrated thread and some comments may be shown as answers.

Prevent a bad image from blowing up the code

1 Answer 51 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Sandra
Top achievements
Rank 1
Sandra asked on 05 Jul 2012, 01:46 PM
Hey,

I was following the example for using a binary image with a listview to display images etc. allowing users to upload, and edit them.

The code is great except in the event the user uploads a bad image, during postback when the listview is displayed it blows up and throws errors saying the binary data is corrupted.

I know there should be a way to grab hold of the data during the ItemDataBound event, and catch the error, and ignore it or substitute the image with something stored on the website like a badimage.jpg

can someone help with this thanks

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 10 Jul 2012, 08:30 AM
Hi,

The better approach is to validate the image upon uploading and to allow saving to the database only if the image was OK.

If you use the ItemDataBound event to validate the images prior displaying them you will need to check every single image from the database and you will do it every time the Grid reloads its data. In the case I am suggesting you will need to check only one time the image prior inserting it into the database and thus you will be sure the image is OK.

How you will validate the image depends on how it is stored and read, you could either user standard validator control or to provide custom validation settings.

Greetings,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ListView
Asked by
Sandra
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or