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