FileUpload Control on Mobile Form

Discussion in 'ASP .Net Web Controls' started by Woodgnome, Aug 24, 2007.

  1. Woodgnome

    Woodgnome Guest

    Hi,

    I am trying to provide the user with a file upload facility on mobile
    devices that will support it. So I have tried using the FileUpload control in
    a device specific section - as follows, but when the form posts back, the
    HasFile proerty is always set to false and the file is nowhere to be seen.
    It would appear that it may be something to do with the fact that the form is
    rendering without enctype="multipart/form-data" on the form tag. Anyone any
    ideas how I might get this to work ?

    <mobile:Form ID="NewForm" runat="server" Title="New Form">

    <mobile:DeviceSpecific ID="DeviceSpecific1" Runat="Server">
    <Choice>
    <FooterTemplate>
    <tr>
    <td>
    <asp:FileUpload ID="fileUpload1"
    runat="server"></asp:FileUpload>
    </br>
    <asp:FileUpload ID="fileUpload2"
    runat="server"></asp:FileUpload>
    </br>
    <asp:FileUpload ID="fileUpload3"
    runat="server"></asp:FileUpload>
    </td>
    </tr>
    </FooterTemplate>
    </Choice>
    </mobile:DeviceSpecific>

    .......
     
    Woodgnome, Aug 24, 2007
    #1
    1. Advertisements

  2. Hi Woodgnome,

    Regarding on the ASP.NET mobile page fileuploading issue, I've performed
    some local tests and did found the same behavior as you mentioned. It seems
    the Mobile Form doesn't allow us to insert our custom attributes into it
    like a standard htmlForm control. I've also tried manually add the
    "enctype="multipart/form-data" " attribute into the mobile form and it was
    also ignored and runtime. BTW, for mobile devices, I notice that few WAP
    or xhtml mp devices support file upload element,

    http://www.developershome.com/wap/wapUpload/wap_upload.asp?page=intro

    so are your web application's target devices HTML enabled? If so, maybe
    you can consider use a standard ASP.NET page(not mobile page) to serve the
    fileupload functionality(since only a simple screen with some text and file
    upload html element are necessary), how do you think?

    Anyway, I'll also help you consult some other mobile engineers to see
    whether there is anything else we can do here, I'll inform you as soon as I
    get any update.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Aug 27, 2007
    #2
    1. Advertisements

  3. Woodgnome

    Woodgnome Guest

    Steven,

    Thanks for the reply. The initial target devices are HTML enabled - but the
    intention was to make the pages available to more devices at a later date.
    I will investigate using a standard asp.net page for now.

    Thanks.
    Woodgnome.
     
    Woodgnome, Aug 28, 2007
    #3
  4. Hi Woodgnome,

    Thanks for your reply.

    Yes, a standard html based ASP.NET page will save much effort. Anyway, I'm
    still doing some further research on this and will inform you if I get any
    new information helpful.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.





    --------------------
     
    Steven Cheng[MSFT], Aug 29, 2007
    #4
  5. Hi Woodgnome,

    Are you still focus on this issue? I've just got some new info. I've
    discussed with a DEV engineer who has ever worked on a similar issue, here
    is a workaround for mobile page to use the fileupload control. See the
    following comments

    ==================================
    The reason upload control can't work on mobile page is the result rendered
    by mobile page is lacking a form property: enctype="multipart/form-data".

    To inject this property you can inherit Html/Chtml/XhtmlMobileTextWriter
    class and override their WriteBeginTag method. The override method is
    something link below:

    public class ChtmlMobileMultipartTextWriter :
    System.Web.UI.MobileControls.Adapters.ChtmlMobileTextWriter
    {
    public ChtmlMobileMultipartTextWriter(System.IO.TextWriter writer,
    MobileCapabilities device)
    : base(writer, device)
    {
    }

    public override void WriteBeginTag(string tag)
    {
    if (tag == null)
    {
    throw new ArgumentNullException("tag");
    }

    base.WriteBeginTag(tag);

    if (tag.Equals("form"))
    {
    WriteAttribute("enctype", "multipart/form-data");
    }
    }
    }

    ==============================

    Hope this still helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.


    --------------------
     
    Steven Cheng[MSFT], Aug 31, 2007
    #5
  6. Hi Woodgnome,

    Does the further info in my last reply helps? If there is anything else we
    can help, please feel free to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.


    --------------------
    ing-Host: tomcatimport2.phx.gbl 10.201.218.182
     
    Steven Cheng[MSFT], Sep 4, 2007
    #6
  7. Woodgnome

    Woodgnome Guest

    Hi Steven,

    Thanks for your posts, this will be helpful if I need to get it working on
    other mobile devices later.

    I have managed to get it working on a standard html based ASP.NET page for
    now.

    However, I have now noticed that the the file name part of the file path
    seams to be restricted to a maximum of 10 chars. I have tried adding the
    maxLength at a custom attribute but this does not seam to have any effect.
    Any ideas how I might be able to allow the user to submit longer file names ?

    Woodgnome.

    P.S. This is on the Windows Mobile 6 Classic Emulator.

     
    Woodgnome, Sep 13, 2007
    #7
  8. Thanks for your followup Woodgnome,

    For the upload control, I haven't got any known of filename size
    limitation(at least not 10 chars). Does this problem only occur for your
    mobile devices? I've tested it on standard aspx page and PC boxes and I can
    submit long-filename files. Just use the below cose to printout the
    filename:
    protected void Button1_Click(object sender, EventArgs e)
    {
    if (FileUpload1.HasFile)
    {
    Response.Write("<br/>filename: " + FileUpload1.FileName);
    }
    }

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.

    --------------------
     
    Steven Cheng[MSFT], Sep 14, 2007
    #8
  9. Woodgnome

    Woodgnome Guest

    Steven,

    Thanks for the reply.

    It's just on the Windows Mobile 6 Classic Emulator. It works OK in a normal
    browser.

    The fileupload.HasFile property is set to false on postback.

    I am guessing that maxLength attribute on the rendered <input> tag is
    defaulting to 10 on the mobile device, but setting on rendering doesnt seam
    to have any effect.

    Woodgnome.

     
    Woodgnome, Sep 14, 2007
    #9
  10. Hi Woodgnome,

    Since Steven is out of office for several days, I will continue work with
    you on this post.

    Let me first summarize the issue so far: you're now able to make the
    FileUpload work on mobile WebForm but the file name length is restricted to
    10.

    Would you please send me a copy of your test web project along with
    detailed configuration (emulator, browser version) to me? I will try to
    reproduce the issue on my side and see if we could find the root cause.
    Thanks for the trouble.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Sep 18, 2007
    #10
  11. Woodgnome

    Woodgnome Guest

    Hi Walter,

    Thanks for the help. It's easy to reproduce just create a new web site, add
    a normal web page, add a file upload control and an asp link button and add
    the code suggested by Steven to the on click event of the link button.

    The emulator is the one include in the Windows Mobile 6 Professional SDK -
    Windows Mobile 6 Classic Emulator and the browser is the one included with
    the emulator.

    When the file name is greater than 10 chars no repsonse is returned because
    the fileuplad.HasFile property is set to false on postback.

    It works OK in IE on a normal desktop.

    I have included the code from the test site below :

    Thanks.
    Woodgnome.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
    Inherits="_Default" ValidateRequest="false"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <br />
    <br />
    <asp:LinkButton ID="LinkButton1" runat="server"
    OnClick="LinkButton1_Click">OK</asp:LinkButton>
    </div>
    </form>
    </body>
    </html>

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
    if (FileUpload1.HasFile)
    {
    Response.Write("<br/>filename: " + FileUpload1.FileName);
    }
    }
    }
     
    Woodgnome, Sep 20, 2007
    #11
  12. Hi Woodgnome,

    So you're not using MobileWebForm? I thought we're discussing FileUpload on
    MobileWebForm.

    If you're using mobile device to access the normal WebForm, I think many
    functions are not supported and the result is unexpected. Though I haven't
    find any document described this 10 characters length limit of uploaded
    file name.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Sep 21, 2007
    #12
  13. Hi Steven
    You have suggested to inject the property enctype="multipart/form-data".
    and inherit Html/Chtml/XhtmlMobileTextWriter
    class and override their WriteBeginTag method.

    Please let me know how I should use this class with FileUpload control,
    where and what should be the code along with the below code you have given.

    My requirement is --> my web application has to upload the file the user
    selects in his PDA(IE Mobile Ver.5).

    Waiting in anticipation.Please help asap.

    Thanks
    T.Jeywin Lizy



     
    T.Jeywin Lizy, Dec 9, 2008
    #13
  14. Woodgnome

    VK Guest

    sir can u please explain how to use this custructor class with the mobile
    form .cs file. I am not able to do that.
    Thanks
     
    VK, Jun 11, 2010
    #14
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.