PDA

View Full Version : [CLOSED] FileUpload HasFile property



mcfromero
Mar 06, 2012, 12:40 PM
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>

Daniil
Mar 06, 2012, 12:52 PM
Hi,

Uploading requires a <form> HTML element.

Please set up FormID="form" for the Click DirectEvent config.

<Click ... IsUpload="true" FormID="form">

Vladimir
Mar 06, 2012, 1:22 PM
Please note there is no FormLayout anymore in Ext.Net v2

mcfromero
Mar 07, 2012, 11:35 AM
Hi Daniil, thank you by reply but "HasFile" property still null.

What can I do?

Thank you



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>

mcfromero
Mar 07, 2012, 11:52 AM
I have copied the Form Exemplo from http://examples2.ext.net/#/Form/FileUploadField/Basic/ into my Asp.Net MVC Application and "hasFile" also returns NULL.

Daniil
Mar 07, 2012, 12:21 PM
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?

mcfromero
Mar 07, 2012, 12:39 PM
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 http://examples2.ext.net/#/Form/FileUploadField/Basic/ page and nothing.

Daniil
Mar 07, 2012, 1:32 PM
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.

mcfromero
Mar 07, 2012, 2:21 PM
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 http://examples2.ext.net/#/Miscellaneous/ProgressBar/Server_Side_Update/, according the uploaded file.

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

Daniil
Mar 07, 2012, 2:39 PM
Please read:
http://forums.ext.net/showthread.php?10948&p=44468&viewfull=1#post44468