1

我正在尝试借助 EXT.NET 2.0 版将文件上传到服务器

在我的情况下:我写在

<ext:FileUploadField ID="FileUploadField1" runat="server" Width="300"><DirectEvents> 


</DirectEvents></ext:FileUploadField>

<FileSelected OnEvent="FileUploadField_FileSelected" IsUpload="true" /> 在FileSelected 不可用时给我错误

我的代码:

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!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>Ext.NET Example</title>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:FileUploadField ID="FileUploadField1" runat="server" Width="300">
            <DirectEvents>
                <FileSelected OnEvent="FileUploadField_FileSelected" IsUpload="true" />
            </DirectEvents>
        </ext:FileUploadField>
    </form>
</body>
</html>

我的 C# 代码:在此 SaveAs 选项中无效,其生成错误:

protected void FileUploadField_FileSelected(object sender, DirectEventArgs e)
    {
        this.FileUploadField1.SaveAs(@"D:\video1.mp4");
    }
4

1 回答 1

4

试试这个:

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
    protected void FileUploadField_FileSelected(object sender, DirectEventArgs e) {
        if (this.FileUploadField1.HasFile)
        {
            HttpPostedFile file = FileUploadField1.PostedFile;
            file.SaveAs(@"d:\" + file.FileName);
        } 
    }
</script>
<!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>Ext.NET Example</title>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" SourceFormatting="True" ScriptMode="Debug" />
        <ext:FileUploadField ID="FileUploadField1" runat="server" Width="300">
            <DirectEvents>
                <Change OnEvent="FileUploadField_FileSelected" IsUpload="true"></Change>
            </DirectEvents>
        </ext:FileUploadField>
    </form>
</body>
</html>
于 2012-11-24T07:24:10.563 回答