Welcome to MSDN Blogs Sign in | Join | Help

Sample for Displaying Images Updated + Screencast

We've recently started getting newer builds of Dynamic Data out to the private testers and soon to more public testers. As a result I've got an updated version of my image controls that I posted on my blog in January. As well I've recorded a screen cast that shows how to use the image controls in a project. Here is the link to the new DbImage project for display images from the database or file system in a Dynamic Data project: DOWNLOAD DBIMAGE.

 

Here is a link to a screencast on how to use the controls: VIEW SCREENCAST.

 

Basic steps for using this in a project:

 

1) Open the zip file and open the redist directory. Copy the DLL from the Bin directory to the Bin directory in your website.

2) In the Redist\FieldTemplates directory copy the files from that directory to the DynamicData\FieldTemplates directory in your website.

3) Open the web.config and add "<add path="ImageHandler.ashx" verb="*" type="DbImageAPI.ImageHandler" />" to the httpHandlers section of your web.config.

 

At this point you have enabled image support in your project. To get it to work you need to add a UIHint attribute to the column in your data model that contains the image. Here are the steps for doing this for the Category table in Northwind.

 

1) Create a partial class for the Category table to extend the Category table in the data model. Right click on the project and click "Add New Item". Select "Class". Type in "Category". Press Add.

2) Add "using System.ComponentModel.DataAnnotations" and "using DbImageAPI" to the using clause section.

3) Change the definition of the class to look like this:

[MetadataType(typeof(CategoryMetadata))]
public partial class Category
{
}

public class CategoryMetadata {
    [UIHint("DbImage")]
    public object Picture { get; set; }
}

What we have done is changed the Category class to be a partial class so it extends the class from the data model. Next we have created a class "CategoryMetadata" that is used to provide metadata for the Category class. The MetadataType attribute is what associates this class with the original Category class. Next we have created a Picture member which we can place metadata on (this is sort of a hack we do today because C# does not support adding attributes on existing members in partial classes, hopefully a future version of C# will address this). Then we apply the UIHint attribute which specifies which field template will be used to render this column.

 

At this point running the application should display the images.

 

The sample download contains both the redist directory that contains all the stuff for adding this support to an existing project. Plus a fully running sample that builds the library. Enjoy!

Published Wednesday, April 09, 2008 12:39 PM by scothu
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Scott Hanselman's Computer Zen - Putting ASP.NET Dynamic Data into Context

# Putting ASP.NET Dynamic Data into Context

There's a lot of folks excited about ASP.NET MVC as an option for creating ASP.NET websites. As I say

Thursday, April 10, 2008 8:25 PM by ASPInsiders

# re: Sample for Displaying Images Updated + Screencast

Very cool!

Thank you very much! :)

Thursday, April 10, 2008 11:16 PM by Rami Abughazaleh

# Taking a look at Dynamic Data

One of the best things about being a programmer is new technologies,&#160; taking a look at exciting

Friday, April 25, 2008 8:12 AM by David Yancey (aka Geebs)

# Taking a look at Dynamic Data

One of the best things about being a programmer is new technologies,&#160; taking a look at exciting

Friday, April 25, 2008 9:06 AM by David.Yancey

# Putting ASP.NET Dynamic Data into Context

There&#39;s a lot of folks excited about ASP.NET MVC as an option for creating ASP.NET websites. As I

Wednesday, April 30, 2008 4:15 PM by Blogs

# re: Sample for Displaying Images Updated + Screencast

Just a note, in order to get the project to successfully add new images to the database I had to remove the UpdatePanel from site.master in the root. Otherwise, the FileUpload control always returns null.

I think it would also work just to make the button perform a postback rather than disabling AJAX for the whole site (but I didn't try).

Monday, June 09, 2008 10:04 PM by Drew Walker

# re: Sample for Displaying Images Updated + Screencast

Hi Scott,

Great screencast and library.

I can't get the images to display from the Category table in Northwind. I have followed all the steps and the Picture colum does display when the page renders but there are no images in any of the rows.

Also when I try to insert into the Category table the Description and Name column get inserted correctly but there is no data being inserted for the Picture column as it comes back as NULL. The file upload control works and lets me select a file etc but there data is not getting sent to the database.

What can I try here to get this going?

thanks - Rob

Tuesday, July 01, 2008 1:11 PM by Robert

# re: Sample for Displaying Images Updated + Screencast

I followed the instructions, but seem to be having an issue similar to Rob.  The images appear, but I can't upload any new images to the db.  In the ExtractValues eventhandler for DbImage_edit, FileUploadEdit.HasFile is ALWAYS false.  Any idea why?

Sunday, July 27, 2008 7:59 PM by RJ

# re: Sample for Displaying Images Updated + Screencast

I had the same issue.

Any solution?

Sunday, October 05, 2008 12:58 PM by Oguzhan

# re: Sample for Displaying Images Updated + Screencast

Same problem for me, FileUploadEdit.HasFile is always false :) Working on a solution to that problem right now.

Friday, October 17, 2008 7:58 AM by Mikael Henriksson

# re: Sample for Displaying Images Updated + Screencast

Any solution to FileUploadEdit.HasFile is always false??

I'm test with DynamicData into VS2008 SP1

And test with DynamicDataFuture idem problem

Thursday, December 04, 2008 1:12 PM by Jose A. Fernandez

# re: Sample for Displaying Images Updated + Screencast

Me again. The problem is FileUpload webcontrol and EnablePartialRendering's ScriptManager

First approximation's solution:

EnablePartialRendering="false" into MAsterPage

:)

Thursday, December 04, 2008 1:29 PM by Jose A. Fernandez

# re: Sample for Displaying Images Updated + Screencast

Other solution

Into PageTemplate: Edit

Pre_Init Event...

Code:

Dim sm As ScriptManager = ScriptManager.GetCurrent(Me.Page)

       sm.EnablePartialRendering = False

Thursday, December 04, 2008 3:33 PM by fernandezja

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker