将文件上传到服务器

将文件上传到服务器

我正在尝试借助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");
    }

最佳答案

试试这个:

<%@ 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>

关于c# - 我试图使用EXT.NET 2.0将文件上传到服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13532891/

10-09 22:44