Has anyone got an up to date example and step by step guide on how to make it possible to view, delete and add ( by uploading a new image) an image which represents an actual image field in the database?
Hi there Yannick86, Telerik had a nice control for that and they already have a field template built that works do a search for it on there forums, I will also look at getting Scots sample working for DD4 in the next week or so.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Something I've found though:
When I for example add a scaffoldColumn to the column CategoryName it does not get scaffolded ... so I'm kinda having the idea that my partial class doesn't even get used. How can I check this? Below is my Partial Class. The 2 bold lines are tryouts which I
found in other examples ... still it does not work.
My code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations; using System.Web.DynamicData;
[MetadataType(typeof(CategoryMetadata))]
public partial class Category
{
}
[TableName("Category")]
public class CategoryMetadata
{
[UIHint("DbImage")]
public object Picture { get; set; }
[ScaffoldColumn(false)]
public object CategoryName { get; set; }
}
Hi Yannick86, I'm going to look at getting Scott Hunters samp[le working in .Net 4 today, but you may also look at the Telerik BinaryImage control they already have a field template for DD4 that works.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
I have in the meantime also gotten mine working. Since I'm totally new at Dynamic Data It wont be my last nooby misstake ... the thing that was wrong with not having the column to show up ... nor being able to for example scaffold(false) another column was
that my partial class didn't have a namespace. Apparantly it has to have exactly the same namespace as the EF edmx designer file has.
The only part that doesn't work now is uploading an image. I can select one, but when updating the record it does not save it, while it does save other columnvalues. PS: I'm doing this with the Northwind database its Categories table ( "Picture" is the image
column )
Did you manage to get the image saved into the database?
yes image saves an displays fine you may need to add the System.Data.Linq to the project also you may need to change the CodeFile to CodeBehind in the markup files I had an issue with namespaces.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Yannick86
Member
565 Points
366 Posts
Image uploading/viewing/deleting
Jun 08, 2011 06:12 PM|LINK
Dear readers,
Has anyone got an up to date example and step by step guide on how to make it possible to view, delete and add ( by uploading a new image) an image which represents an actual image field in the database?
I have found the following blog post by Scott Hunter, but I just can't get it working because I think it is not up to date.
http://blogs.msdn.com/b/scothu/archive/2008/01/14/sample.aspx
I'd like to achieve this in Visual Studio 2010 with .NET 4.0 ... this is only a preference, so any other suggestions are alsoo welcome.
Any help will be greatly appreciated.
Thanks in advance,
-Yannick
rickjackson
Participant
1362 Points
405 Posts
Re: Image uploading/viewing/deleting
Jun 08, 2011 06:55 PM|LINK
Hello Yanni, check out these links :
Now Deleting Files from the Server check out these links
Let us know incase of issues...
regards,
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Image uploading/viewing/deleting
Jun 08, 2011 09:35 PM|LINK
Hi there Yannick86, Telerik had a nice control for that and they already have a field template built that works do a search for it on there forums, I will also look at getting Scots sample working for DD4 in the next week or so.
Always seeking an elegant solution.
Yannick86
Member
565 Points
366 Posts
Re: Image uploading/viewing/deleting
Jun 09, 2011 10:49 AM|LINK
Nice, can't wait for it :)
I've retried the whole thing in 3.5 and again it all went perfectly just like the tutorial describes @ http://blogs.msdn.com/b/scothu/archive/2008/04/09/sample-for-displaying-images-updated-screencast.aspx . But yet again I'm having the same issue. I just can't get the column "picture" to show up. Not when I'm viewing and not when I'm editting.
Something I've found though:
When I for example add a scaffoldColumn to the column CategoryName it does not get scaffolded ... so I'm kinda having the idea that my partial class doesn't even get used. How can I check this? Below is my Partial Class. The 2 bold lines are tryouts which I found in other examples ... still it does not work.
My code:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using System.Web.DynamicData; [MetadataType(typeof(CategoryMetadata))] public partial class Category { } [TableName("Category")] public class CategoryMetadata { [UIHint("DbImage")] public object Picture { get; set; } [ScaffoldColumn(false)] public object CategoryName { get; set; } }sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Image uploading/viewing/deleting
Jun 09, 2011 10:56 AM|LINK
Hi Yannick86, I'm going to look at getting Scott Hunters samp[le working in .Net 4 today, but you may also look at the Telerik BinaryImage control they already have a field template for DD4 that works.
Always seeking an elegant solution.
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Image uploading/viewing/deleting
Jun 09, 2011 12:03 PM|LINK
Hi Yannick86, I have the old DB Image sample working now with EF and Linq to SQL
Always seeking an elegant solution.
Yannick86
Member
565 Points
366 Posts
Re: Image uploading/viewing/deleting
Jun 09, 2011 12:19 PM|LINK
I have in the meantime also gotten mine working. Since I'm totally new at Dynamic Data It wont be my last nooby misstake ... the thing that was wrong with not having the column to show up ... nor being able to for example scaffold(false) another column was that my partial class didn't have a namespace. Apparantly it has to have exactly the same namespace as the EF edmx designer file has.
The only part that doesn't work now is uploading an image. I can select one, but when updating the record it does not save it, while it does save other columnvalues. PS: I'm doing this with the Northwind database its Categories table ( "Picture" is the image column )
Did you manage to get the image saved into the database?
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Image uploading/viewing/deleting
Jun 09, 2011 12:32 PM|LINK
yes image saves an displays fine you may need to add the System.Data.Linq to the project also you may need to change the CodeFile to CodeBehind in the markup files I had an issue with namespaces.
Always seeking an elegant solution.
Yannick86
Member
565 Points
366 Posts
Re: Image uploading/viewing/deleting
Jun 09, 2011 02:25 PM|LINK
You've done this with the northwind db with a column of type "image"?
And what type does your column have in the edmx file? ( EF )
Thanks in advance.
Btw I've gotten further thanks a post of you somewhere stating the following:
DynamicDataFutures.DisablePartialRenderingForUpload(this, GridDataSource.GetTable()); ==> This has to be placed in the init method of the edit page.
Once this is put in place I'm getting the next problem when updating the record once an image is uploaded:
Error while setting property 'Picture': 'Object of type
'System.Data.Linq.Binary' cannot be converted to type 'System.Byte[]'.'.
sjnaughton
All-Star
27330 Points
5459 Posts
MVP
Re: Image uploading/viewing/deleting
Jun 09, 2011 02:44 PM|LINK
yep :) e-mail me and I will send you the sample, I'm getting permission from Scott Hunter top put it on NuGet.
Always seeking an elegant solution.