[CLOSED] FileUpload HasFile property

  1. #1

    [CLOSED] FileUpload HasFile property

    Hello,

    I'm trying upload a file using FileUploadField but the "hasFile" property is always null.


    In the following case I would like the user select a file so after the button click I do my job. This can happen both in "Server side methods" or in current "Controller" (i'm using asp.net MVC)

    I already read all topics about this issue but the problem persists.

    Thank you



    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Xml.Xsl" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="System.Linq" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <script runat="server">
    
    
        protected void ReadFile(object sender, DirectEventArgs e)
        {
            GetFile();
        }
    
        [DirectMethod]
        protected void btnGetFile_click(object sender, DirectEventArgs args)
        {
            GetFile();
        }
    
        private void GetFile()
        {
            if (fileUpload.HasFile) //Always null
            {
                byte[] fileByte = fileUpload.FileBytes;
                string fileName = fileUpload.FileName;
                System.IO.Stream fileContent = fileUpload.FileContent;
            }
        }
    </script>
    <html>
    <head runat="server">
        <title>UploadView</title>
    </head>
    <body>
        <div>
            <ext:ResourceManager ID="resourceUploadView" runat="server" IDMode="Explicit" />
            <ext:FormPanel ID="form" runat="server" Layout="FormLayout">
                <Content>
                    <ext:FileUploadField ID="fileUpload" runat="server">
                        <DirectEvents>
                            <FileSelected OnEvent="ReadFile" IsUpload="true" />
                        </DirectEvents>
                    </ext:FileUploadField>
                    <ext:Button ID="btnGetFile" runat="server" Text="Get File">
                        <DirectEvents>
                            <Click OnEvent="btnGetFile_click" IsUpload="true"></Click>
                        </DirectEvents>
                    </ext:Button>
                </Content>
            </ext:FormPanel>
        </div>
    </body>
    </html>
    Last edited by Daniil; Mar 10, 2012 at 2:17 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Uploading requires a <form> HTML element.

    Please set up FormID="form" for the Click DirectEvent config.
    <Click ... IsUpload="true" FormID="form">
  3. #3
    Please note there is no FormLayout anymore in Ext.Net v2
    Last edited by Vladimir; Mar 06, 2012 at 1:29 PM.
  4. #4

    not worked

    Hi Daniil, thank you by reply but "HasFile" property still null.

    What can I do?

    Thank you


    Quote Originally Posted by mcfromero View Post
    Hello,

    I'm trying upload a file using FileUploadField but the "hasFile" property is always null.


    In the following case I would like the user select a file so after the button click I do my job. This can happen both in "Server side methods" or in current "Controller" (i'm using asp.net MVC)

    I already read all topics about this issue but the problem persists.

    Thank you



    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Xml.Xsl" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="System.Linq" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <script runat="server">
    
    
        protected void ReadFile(object sender, DirectEventArgs e)
        {
            GetFile();
        }
    
        [DirectMethod]
        protected void btnGetFile_click(object sender, DirectEventArgs args)
        {
            GetFile();
        }
    
        private void GetFile()
        {
            if (fileUpload.HasFile) //Always null
            {
                byte[] fileByte = fileUpload.FileBytes;
                string fileName = fileUpload.FileName;
                System.IO.Stream fileContent = fileUpload.FileContent;
            }
        }
    </script>
    <html>
    <head runat="server">
        <title>UploadView</title>
    </head>
    <body>
        <div>
            <ext:ResourceManager ID="resourceUploadView" runat="server" IDMode="Explicit" />
            <ext:FormPanel ID="form" runat="server" Layout="FormLayout">
                <Content>
                    <ext:FileUploadField ID="fileUpload" runat="server">
                        <DirectEvents>
                            <FileSelected OnEvent="ReadFile" IsUpload="true" />
                        </DirectEvents>
                    </ext:FileUploadField>
                    <ext:Button ID="btnGetFile" runat="server" Text="Get File">
                        <DirectEvents>
                            <Click OnEvent="btnGetFile_click" IsUpload="true"></Click>
                        </DirectEvents>
                    </ext:Button>
                </Content>
            </ext:FormPanel>
        </div>
    </body>
    </html>
  5. #5
    I have copied the Form Exemplo from https://examples2.ext.net/#/Form/FileUploadField/Basic/ into my Asp.Net MVC Application and "hasFile" also returns NULL.
  6. #6
    Please clarify how do you open that page?

    Please try to define:
    <form id="formUpload" class="x-hidden"></form>
    on the page and set up FormID="formUpload" for the DirectEvent.

    Does it help?

    What Ext.NET sources do you use?
  7. #7
    I'm using Pro.

    And I'm openning the page directly by the mvc route "http://localhost:2702/Task/UploadView".

    As I was said, I have copied the last exemple from https://examples2.ext.net/#/Form/FileUploadField/Basic/ page and nothing.
  8. #8
    Confirmed, the standard WebForm way to upload doesn't work in MVC.

    Please use a controller action to upload a file.

    It can look something like this:
    http://forums.ext.net/showthread.php?12018

    As well, you can use DirectEvent with a respective Url.
  9. #9
    Thank Daniil, I already was tried by this approach and really works, but I was trying by "WebForm way" because I need show a progress bar like https://examples2.ext.net/#/Miscella...r_Side_Update/, according the uploaded file.

    But I have no idea what/how to do. Can you help me?
  10. #10

Similar Threads

  1. [CLOSED] FileUpload property under FormPanel doesn't found
    By Daly_AF in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 06, 2012, 3:31 PM
  2. [CLOSED] Missed FileUpload property of FormPanel
    By Daly_AF in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 25, 2012, 11:57 AM
  3. Replies: 0
    Last Post: Mar 02, 2012, 1:11 PM
  4. Replies: 3
    Last Post: Nov 29, 2010, 3:52 PM
  5. [CLOSED] FormPanel FileUpload Property
    By turione in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Apr 10, 2009, 7:42 PM

Tags for this Thread

Posting Permissions