Anyone know how to use the FileImageAPI Edit Funtionality?http://forums.asp.net/t/1284069.aspx/1?Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Wed, 08 Oct 2008 08:01:51 -040012840692462274http://forums.asp.net/p/1284069/2462274.aspx/1?Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hello,</p> <p>&nbsp;I am trying to use the FileImage API instead of DBImage. Did anyone used the FileImage? I am having problem with the FileImage_Edit field templates? If anyone can share their code for this user control I will be grateful.</p> <p>&nbsp;</p> <p>Thanks,</p> <p>&nbsp;</p> 2008-07-02T13:21:54-04:002462535http://forums.asp.net/p/1284069/2462535.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hi Tareq,</p> <p>Please see this post <a id="bp___ctl00___RecentPosts___postlist___EntryItems_ctl13_PostTitle" href="http://blogs.msdn.com/scothu/archive/2008/01/14/sample.aspx"> Sample for Displaying Images from the Database using Dynamic Data</a>&nbsp;by Scott Hunter (bear in mind that this is an old post and some of the Attributes have changed name and parameters)</p> <p>Here is my metadata class for the table <strong>FileImageTest</strong> </p> <pre></pre> <pre class="prettyprint">using System.ComponentModel; using System.ComponentModel.DataAnnotations; using Microsoft.Web.DynamicData; [MetadataType(typeof(FileImageTestMD))] public partial class FileImageTest : INotifyPropertyChanging, INotifyPropertyChanged { } public class FileImageTestMD { public object Id {get;set;} public object Description {get;set;} [UIHint(&quot;FileImage&quot;)] [ImageUrl(&quot;~/images/{0}.png&quot;)] [ImageFormat(50,50)] public object filePath {get;set;} }</pre> <p><strong>Note:</strong> that there is NO&nbsp;edit facility in the FileImage at the moment. I've had an idea and will have a go and publish here and on my blog.</p> <p><strong>Another Note:</strong> there are two methods to do the edit:</p> <ol> <li>Give a list of images from the specified folder [ImageUrl(<span class="st">&quot;~/images/{0}.png&quot;</span>)] and let the user choose </li><li>Let the user upload the file to the [ImageUrl(<span class="st">&quot;~/images/{0}.png&quot;</span>)] folder and the pass the filename to the DB field.</li></ol> <p>Hope this helps [:D]</p> 2008-07-02T14:50:46-04:002462550http://forums.asp.net/p/1284069/2462550.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Thank you for your response. I have already implemented&nbsp;displaying image&nbsp; using FileImage as suggested in Scott Hunters Blog. It is the edit part that I am trying to figure out. If you have the edit functionality I would like to see that.</p> <p>Thanks</p> 2008-07-02T14:56:55-04:002462588http://forums.asp.net/p/1284069/2462588.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>I'm just working on it now hopefully I will have it soon to show you [:)]</p> 2008-07-02T15:09:28-04:002462838http://forums.asp.net/p/1284069/2462838.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>sjnaughton</h4> <p><strong>Another Note:</strong> there are two methods to do the edit:</p> <ol> <li>Give a list of images from the specified folder [ImageUrl(<span class="st">&quot;~/images/{0}.png&quot;</span>)] and let the user choose </li><li>Let the user upload the file to the [ImageUrl(<span class="st">&quot;~/images/{0}.png&quot;</span>)] folder and the pass the filename to the DB field.</li></ol> <p></p> </blockquote> <p></p> <p>This is option 1. </p> <pre class="prettyprint">using System; using System.Collections.Specialized; using System.IO; using System.Linq; using System.Web.DynamicData; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.Web.DynamicData; public partial class FileImage_Edit : FieldTemplateUserControl { public override Control DataControl { get { return RadioButtonList1; } } protected override void OnDataBinding(EventArgs e) { base.OnDataBinding(e); //check if image exists if (FieldValue == null) return; //format image url string url; var metadata = MetadataAttributes.OfType&lt;ImageUrlAttribute&gt;().FirstOrDefault(); if (metadata == null || String.IsNullOrEmpty(metadata.UrlFormat)) return; // get images folder String imagesDir = metadata.UrlFormat.Substring(0, metadata.UrlFormat.LastIndexOf(&quot;/&quot;) &#43; 1); // get a list of images in the ImageUrlAttribute folder var dirInfo = new DirectoryInfo(Server.MapPath(imagesDir)); var imagesFolder = ResolveUrl(imagesDir); var files = dirInfo.GetFiles(); int width = 50; int height = 50; var imageFormat = MetadataAttributes.OfType&lt;ImageFormatAttribute&gt;().FirstOrDefault();</pre><pre class="prettyprint"> <SPAN class=kwd>if</SPAN> (imageFormat != <SPAN class=kwd>null</SPAN>) { width = imageFormat.DisplayWidth; height = imageFormat.DisplayHeight; } <SPAN class=kwd>foreach</SPAN> (FileInfo file <SPAN class=kwd>in</SPAN> files) { String fileName = file.Name.Substring(0, file.Name.LastIndexOf(<SPAN class=st>"."</SPAN>)); String img = String.Format ( <SPAN class=st>"&amp;lt;img src='{0}' alt='{1}' width='{2}' height='{3}' /&gt;"</SPAN>, imagesFolder + file.Name, fileName, width, height ); var li = <SPAN class=kwd>new</SPAN> ListItem(img, fileName); <SPAN class=kwd>this</SPAN>.RadioButtonList1.Items.Add(li); } } <SPAN class=kwd>protected override void</SPAN> ExtractValues(IOrderedDictionary dictionary) { dictionary[Column.Name] = RadioButtonList1.SelectedValue; } <SPAN class=kwd>protected void</SPAN> RadioButtonList1_DataBound(<SPAN class=kwd>object</SPAN> sender, EventArgs e) { <SPAN class=kwd>if</SPAN> (FieldValue != <SPAN class=kwd>null</SPAN>) { var selectedImage = ((String)FieldValue).Substring(0, ((String)FieldValue).LastIndexOf(<SPAN class=st>"."</SPAN>)); <SPAN class=kwd>for</SPAN> (<SPAN class=kwd>int</SPAN> i = 0; i &lt; RadioButtonList1.Items.Count; i++) { <SPAN class=cmt>// set select image </SPAN> <SPAN class=kwd>if</SPAN> (selectedImage == RadioButtonList1.Items[i].Value) { RadioButtonList1.Items[i].Selected = <SPAN class=kwd>true</SPAN>; } } } } }</pre> <P mce_keep="true">Above is the FileImage_Edit.ascx.cs</P><pre class="prettyprint"><SPAN class=dir>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="FileImage_Edit.ascx.cs" Inherits="FileImage_Edit" %&gt;</SPAN> &lt;<SPAN class=tag>asp:RadioButtonList</SPAN><SPAN class=attr> ID=</SPAN><SPAN class=attrv>"RadioButtonList1"</SPAN><SPAN class=attr> runat=</SPAN><SPAN class=attrv>"server"</SPAN> <SPAN class=attr> RepeatDirection=</SPAN><SPAN class=attrv>"Horizontal"</SPAN> <SPAN class=attr> RepeatLayout=</SPAN><SPAN class=attrv>"Flow"</SPAN>&gt; &lt;/<SPAN class=tag>asp:RadioButtonList</SPAN>&gt;</pre> <P mce_keep="true">Above is the FileImage_Edit.ascx</P> <P mce_keep="true">Of course you will need a folder with some images in here is my Metadata also:</P> <P mce_keep="true"><pre class="prettyprint">[MetadataType(<SPAN class=kwd>typeof</SPAN>(FileImageTestMD))] <SPAN class=kwd>public</SPAN> partial <SPAN class=kwd>class</SPAN> FileImageTest : INotifyPropertyChanging, INotifyPropertyChanged { } <SPAN class=kwd>public class</SPAN> FileImageTestMD { <SPAN class=kwd>public object</SPAN> Id {<SPAN class=kwd>get</SPAN>;<SPAN class=kwd>set</SPAN>;} <SPAN class=kwd>public object</SPAN> Description {<SPAN class=kwd>get</SPAN>;<SPAN class=kwd>set</SPAN>;} [UIHint(<SPAN class=st>"FileImage"</SPAN>)] [ImageUrl(<SPAN class=st>"~/images/{0}.png"</SPAN>)] [ImageFormat(50,50)] <SPAN class=kwd>public object</SPAN> filePath {<SPAN class=kwd>get</SPAN>;<SPAN class=kwd>set</SPAN>;} }</pre> <p>Hope this helps I'll blog a bit more about this and option two in the next few days</p> 2008-07-02T16:23:47-04:002462847http://forums.asp.net/p/1284069/2462847.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>FileImage is only ready only in the DbImageAPI I have posted for displaying images off the harddrive. You would have to implement you own FileImage_Edit functionality. I see Steve has posted some code that might do that for you.</p> 2008-07-02T16:27:11-04:002463221http://forums.asp.net/p/1284069/2463221.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Thank you very much. I will try this and see if it works for me.</p> 2008-07-02T18:54:38-04:002463270http://forums.asp.net/p/1284069/2463270.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>I've nearly got the file upload version done and will post it as soon as&nbsp;I have. [:D]</p> 2008-07-02T19:14:59-04:002463814http://forums.asp.net/p/1284069/2463814.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Thank you Steve. Appreciate the help. I will be looking forward to that post. I have to do this in VB so I will convert the code you posted.</p> 2008-07-03T01:36:55-04:002465203http://forums.asp.net/p/1284069/2465203.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hi Tareq, I've posted the final bit upon my blog <a href="http://csharpbits.notaclue.net/2008/07/dynamic-data-fileimageedit.html"> Dynamic Data: FileImage_Edit FieldTemplate</a>&nbsp;hope this is what you were looking for.</p> 2008-07-03T12:36:13-04:002465822http://forums.asp.net/p/1284069/2465822.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hi Steve,</p> <p>This is just what I was&nbsp;looking for, and posted only&nbsp;2 hours before I needed it, good timing!&nbsp;And a &quot;local&quot; too!</p> <p>One small thing... there is a slight typo in your code listing for <font color="#2b91af" size="2"> FileImageTypesAttribute</font> where you have got <font size="2">DefaultExtansions rather than <font size="2">DefaultExtensions. </font></font></p> <p>Many thanks,</p> <p>Rob&nbsp;</p> 2008-07-03T16:10:48-04:002465969http://forums.asp.net/p/1284069/2465969.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Yep I can't type, I must have spell checked some of the code when I posted it to my blog but not all of it; sorry I try harder next time [:D]</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>robroe</h4> there is a slight typo in your code listing for <font color="#2b91af" size="2">FileImageTypesAttribute</font> where you have got <font size="2">DefaultExtansions rather than <font size="2">DefaultExtensions. </font> </font></blockquote> <p>I just fixed it an reposted, Oh yeh and I can't spell either. [I wish this editor had a spell checker] [;)]</p> 2008-07-03T17:28:43-04:002471715http://forums.asp.net/p/1284069/2471715.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hey Steve,</p> <p>Thank you very much for the code. I think I am missing something. This project is available for download in several places and I am not sure which one is the latest version.</p> <p>&nbsp;I am getting errors: </p> <p>The type or namespace name 'FileImage' could not be found (are you missing a using directive or an assembly reference?)&nbsp;</p> <p>I think I am missing a class file. Can you point me to the latest download or email me the the complete project.</p> <p>Thanks again,</p> <p>Tareq</p> 2008-07-07T13:13:56-04:002471852http://forums.asp.net/p/1284069/2471852.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hi Tareq, e-mail me by clicking <a href="http://forums.asp.net/members/sjnaughton.aspx#"> <font color="#034efa">Send sjnaughton an email</font></a> and I'll reply with the website file zipped up. [:D]</p> 2008-07-07T14:01:00-04:002475784http://forums.asp.net/p/1284069/2475784.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hey Steve, thanks a lot. I finally got it to work in VB. Now for the next step I need to use this FileImage image API with a custom page. It don't seem to work if I turn off the autogeneraterow to false. Is there a easy way to configure the custom page to use this API?</p> <p>Thanks,</p> <p>Tareq</p> 2008-07-08T22:37:36-04:002475802http://forums.asp.net/p/1284069/2475802.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>To use Dynamic Data with autogenerate turned off you have two options:</p> <p>1) Put a DynamicField into the list of columns for the GridView/DetailsView and specify the fieldname.</p> <p>2) Create a TemplateField and put a DynamicControl into the list of columns for the GridView/DetailsView and specify the fieldname.</p> <p>If this doesn't answer your question then show us an example of your data control with autogenerate turned off.</p> 2008-07-08T23:07:11-04:002475820http://forums.asp.net/p/1284069/2475820.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Tareq</h4> It don't seem to work if I turn off the autogeneraterow to false. Is there a easy way to configure the custom page to use this API?</blockquote> <p>It will not work if&nbsp;you set <strong>AutogenerateRow</strong> to <strong>false</strong> you must set up the columns using <strong>DynamicControl</strong> or <strong>DynamicField</strong> this allows the the GridView etc to put the correct <strong>FieldTemplate</strong> in place. To do this on a new page you will need&nbsp;to add an <strong>DynamicDataManager</strong> and point it at the the <strong>GridView</strong> etc control see below.<pre class="prettyprint">DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/);</pre> <P mce_keep="true">whether your customising a page or creating a completely new page it's&nbsp;the same after that you must add the columns you want to display as in a normal customised gridview but replace the normal controls in the <STRONG>ItemTemplate/EditTemplate</STRONG> etc with <STRONG>DynmaicField/DynamicControl</STRONG> see below for an example of the columns collection.</P> <P mce_keep="true"><pre class="prettyprint">&lt;<SPAN class=tag>Columns</SPAN>&gt; &lt;<SPAN class=tag>asp:TemplateField</SPAN>&gt; &lt;<SPAN class=tag>ItemTemplate</SPAN>&gt; &lt;<SPAN class=tag>asp:HyperLink</SPAN><SPAN class=attr> ID=</SPAN><SPAN class=attrv>"EditHyperLink"</SPAN><SPAN class=attr> runat=</SPAN><SPAN class=attrv>"server"</SPAN><SPAN class=attr> NavigateUrl=</SPAN><SPAN class=attrv>'<SPAN class=dir>&lt;%#</SPAN> table.GetActionPath(PageAction.Edit, GetDataItem()) <SPAN class=dir>%&gt;</SPAN>'</SPAN><SPAN class=attr> Text=</SPAN><SPAN class=attrv>"Edit"</SPAN> /&gt;&amp;nbsp; &nbsp; &lt;<SPAN class=tag>asp:LinkButton</SPAN><SPAN class=attr> ID=</SPAN><SPAN class=attrv>"DeleteLinkButton"</SPAN><SPAN class=attr> runat=</SPAN><SPAN class=attrv>"server"</SPAN><SPAN class=attr> CommandName=</SPAN><SPAN class=attrv>"Delete"</SPAN><SPAN class=attr> CausesValidation=</SPAN><SPAN class=attrv>"false"</SPAN><SPAN class=attr> Text=</SPAN><SPAN class=attrv>"Delete"</SPAN><SPAN class=attr> OnClientClick=</SPAN><SPAN class=attrv>'return confirm("Are you sure you want to delete this item?");'</SPAN> /&gt;&amp;nbsp; &nbsp; &lt;<SPAN class=tag>asp:HyperLink</SPAN><SPAN class=attr> ID=</SPAN><SPAN class=attrv>"DetailsHyperLink"</SPAN><SPAN class=attr> runat=</SPAN><SPAN class=attrv>"server"</SPAN><SPAN class=attr> NavigateUrl=</SPAN><SPAN class=attrv>'<SPAN class=dir>&lt;%#</SPAN> table.GetActionPath(PageAction.Details, GetDataItem()) <SPAN class=dir>%&gt;</SPAN>'</SPAN><SPAN class=attr> Text=</SPAN><SPAN class=attrv>"Details"</SPAN> /&gt; &lt;/<SPAN class=tag>ItemTemplate</SPAN>&gt; &lt;/<SPAN class=tag>asp:TemplateField</SPAN>&gt; &lt;<SPAN class=tag>asp:TemplateField</SPAN>&gt; &lt;<SPAN class=tag>ItemTemplate</SPAN>&gt; &lt;<SPAN class=tag>asp:DynamicControl</SPAN><SPAN class=attr> ID=</SPAN><SPAN class=attrv>"DynamicControl1"</SPAN><SPAN class=attr> runat=</SPAN><SPAN class=attrv>"server"</SPAN><SPAN class=attr> Mode=</SPAN><SPAN class=attrv>"ReadOnly"</SPAN><SPAN class=attr> DataField=</SPAN><SPAN class=attrv>"Description"</SPAN>&gt; &lt;/<SPAN class=tag>asp:DynamicControl</SPAN>&gt; &lt;/<SPAN class=tag>ItemTemplate</SPAN>&gt; &lt;/<SPAN class=tag>asp:TemplateField</SPAN>&gt; &lt;<SPAN class=tag>asp:TemplateField</SPAN>&gt; &lt;<SPAN class=tag>ItemTemplate</SPAN>&gt; &lt;<SPAN class=tag>asp:DynamicControl</SPAN><SPAN class=attr> ID=</SPAN><SPAN class=attrv>"DynamicControl2"</SPAN><SPAN class=attr> runat=</SPAN><SPAN class=attrv>"server"</SPAN><SPAN class=attr> Mode=</SPAN><SPAN class=attrv>"ReadOnly"</SPAN><SPAN class=attr> DataField=</SPAN><SPAN class=attrv>"filePath"</SPAN>&gt; &lt;/<SPAN class=tag>asp:DynamicControl</SPAN>&gt; &lt;/<SPAN class=tag>ItemTemplate</SPAN>&gt; &lt;/<SPAN class=tag>asp:TemplateField</SPAN>&gt; &lt;/<SPAN class=tag>Columns</SPAN>&gt;</pre>&nbsp;</p> 2008-07-08T23:37:47-04:002475883http://forums.asp.net/p/1284069/2475883.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Thanks guys. That resolved the issue. You guys are awesome.</p> 2008-07-09T01:20:12-04:002481317http://forums.asp.net/p/1284069/2481317.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>Hey Guys,</p> <p>&nbsp;I stumbled on another issue. Due to the line in insert.aspx</p> <font size="2"> <p>FileImageHelper.DisablePartialRenderingForUpload(</font><font color="#0000ff" size="2">Me</font><font size="2">, table) is creating issue for me to to do a partial update on a template field&nbsp;inside the detailsview. More details of this post is posted here:</font></p> <p><font size="2"><a href="http://forums.asp.net/t/1288000.aspx">http://forums.asp.net/t/1288000.aspx</a></font></p> <p><font size="2">&nbsp;Whenever I try to update another updatepanel it keeps refreshing the main updatepanel. Any ideas how this can be resolved?</font></p> <p>Thanks again,</p> <p>Tareq<font size="2"></p> </font><font size="2"> <p>&nbsp;</p> </font> 2008-07-10T19:34:42-04:002481333http://forums.asp.net/p/1284069/2481333.aspx/1?Re+Anyone+know+how+to+use+the+FileImageAPI+Edit+Funtionality+Re: Anyone know how to use the FileImageAPI Edit Funtionality? <p>The FileImageHelper.DisablePartialRenderingForUpload(<font color="#0000ff" size="2">Me</font><font size="2">, table) line disables partial rendering whenever there is a DBImage or FileImage FieldTemplate on the page due to the FileUpload having a security issue with partial render, so it's by design that the main updatepanel updates.</font></p> 2008-07-10T19:44:16-04:00