gpt4 book ai didi

c# - 我尝试使用 EXT.NET 2.0 将文件上传到服务器

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:06 27 4
gpt4 key购买 nike

我正在尝试借助 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com