Dynamic Data File Upload Help

Last post 06-17-2008 12:05 PM by scothu. 7 replies.

Sort Posts:

  • Dynamic Data File Upload Help

    05-14-2008, 11:31 AM
    • Loading...
    • Albinotux
    • Joined on 07-16-2007, 1:31 PM
    • Posts 14

    I am trying to save binary data to the database using a custom field type, however I am unable to get the FileUpload control to actually upload the file. I looked at the DbImage sample, but was unable get it to work (the page to post back when the update link is clicked). What am I missing?

     Excerpt from filePDF_Edit.ascx.cs

    1    protected override void ExtractValues(IOrderedDictionary dictionary)
    2 {
    3 if (FileUpload1.HasFile) {
    4 dictionary[Column.Name] = new System.Data.Linq.Binary(FileUpload1.FileBytes);
    5 }
    6 }

      

     filePDF_Edit.ascx:

    1    <%@ Control Language="C#" CodeBehind="filePDF_Edit.ascx.cs" Inherits="MaterialsWeb2.filePDF_EditField" %>
    2
    3 <asp:HyperLink runat="server" ID="Hyperlink1"
    4 Text="PDF" ImageUrl="~/Images/go.gif" />
    5
    6 <asp:FileUpload ID="FileUpload1" runat="server" />
    7
      
  • Re: Dynamic Data File Upload Help

    05-14-2008, 12:41 PM
    Answer
    • Loading...
    • scothu
    • Joined on 12-10-2007, 1:54 AM
    • Redmond, WA
    • Posts 106
    • AspNetTeam

    Our default templates are placed inside an UpdatePanel with partial rendering enabled and the FileUpload control is not supported inside the UpdatePanel. In my DbImage sample I have the partial rendering disabled which is why it should work. In your case disable partial rendering on the update panel I think you will see the correct behavior.

    Scott Hunter
    ASP.NET
  • Re: Dynamic Data File Upload Help

    05-14-2008, 1:07 PM
    • Loading...
    • Albinotux
    • Joined on 07-16-2007, 1:31 PM
    • Posts 14

     Thank you, that was it.

  • Re: Dynamic Data File Upload Help

    06-13-2008, 7:24 AM
    • Loading...
    • GiovanniQ
    • Joined on 06-13-2008, 6:41 AM
    • Posts 9

    I downloaded DBImageAPI + related Northwind example Website, where partial rendering was enabled, causing the wrong behavior, so what implies disabling partial rendering in a Dynamic Web Site?

    Thanks

  • Re: Dynamic Data File Upload Help

    06-13-2008, 1:13 PM
    • Loading...
    • scothu
    • Joined on 12-10-2007, 1:54 AM
    • Redmond, WA
    • Posts 106
    • AspNetTeam

    The asp:FileUpload control does not work with partial render do to security issues. See Eilon from our teams post on this: http://weblogs.asp.net/leftslipper/archive/2007/03/30/why-don-t-file-uploads-work-during-async-postbacks.aspx. I'm going to re-post this sample later today that contains a fix for this. Basically some boiler plate code added to the page templates that detect if a DbImage control is on the page and disables partial rendering in that case.

    Scott Hunter
    ASP.NET
  • Re: Dynamic Data File Upload Help

    06-13-2008, 2:24 PM
    • Loading...
    • GiovanniQ
    • Joined on 06-13-2008, 6:41 AM
    • Posts 9

    OK well :-)

    Will I find the new version in http://code.msdn.microsoft.com/dynamicdata/Wiki/View.aspx?title=NET35Samples ?

    At the moment the scaffold and dbimage download links are inverted.

    In LinqImageHelper class I have changed something due an incorrect cast in case of guid primary key

    object value;

    if (member.ColumnType.Name == "Guid")

    value = new Guid(primarykeyvalue);

    else

    value = Convert.ChangeType(primarykeyvalue, member.TypeCode, CultureInfo.InvariantCulture);

  • Re: Dynamic Data File Upload Help

    06-15-2008, 10:13 AM
    • Loading...
    • GiovanniQ
    • Joined on 06-13-2008, 6:41 AM
    • Posts 9

    It would be great to have also a file size and extension control on uploading.

    Ciao

  • Re: Dynamic Data File Upload Help

    06-17-2008, 12:05 PM
    • Loading...
    • scothu
    • Joined on 12-10-2007, 1:54 AM
    • Redmond, WA
    • Posts 106
    • AspNetTeam

    I've posted an update to DbImage on the Code Gallery site: https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=dynamicdata&ReleaseId=994.

    Here is the lis of changes:

    1) Fixed an issue that caused DbImage not to work when the primary column for the table is a GUID.

    2) Added support for compound primary keys (primary key that is more then one column in the table).

    3) Added support for Entity Framework (previous release would display images in Entity Framework but fail to update them).

    4) The asp:FileUpload control does not work correctly inside of UpdatePanels with partial rendering turned on. By default the templates in Dynamic Data are enclosed in UpdatePanels with partial rendering turned on. This means that uploading of images will fail unless partial rendering is disabled. The new sample adds a helper method call in the Page_Init of the Insert, Edit and ListDetails page templates. This helper call looks to see if any of the displayed columns are DbImage columns and if so turns off partial rendering for the page.

     

    Scott Hunter
    ASP.NET
Page 1 of 1 (8 items)