这是文件上传字段
<ext:FileUploadField runat="server" ID="fufVideo" LabelWidth="130" FieldLabel="Video Path"></ext:FileUploadField>
<ext:FileUploadField runat="server" ID="fufPhoto" LabelWidth="130" FieldLabel="Title Image Path"></ext:FileUploadField>
<%--<ext:TextField runat="server" ID="txtDisplayOrder" LabelWidth="130" FieldLabel="Display Order" AllowBlank="false"></ext:TextField>--%>
<ext:Checkbox ID="chkOnHomePage" runat="server" LabelWidth="130" FieldLabel="Show On Home Page?"></ext:Checkbox>
<ext:Checkbox ID="chkIsActive" runat="server" LabelWidth="130" FieldLabel="Is Active?"></ext:Checkbox>
<ext:DateMenu ID="dateAdd" runat="server" LabelWidth="90" FieldLabel="Added Date"></ext:DateMenu>
<ext:DatePicker ID="dateExpired" runat="server" LabelWidth="90" FieldLabel="Expired Date"></ext:DatePicker>
这是背后的代码
string videoUrl = "";
string imageUrl = "";
Client client = null;
string folderName = "";
if (HttpContext.Current.Session["Client"] != null)
{
client = (Client)HttpContext.Current.Session["Client"];
//folderName = client.ShortCode + client.ClientId;
folderName = client.ShortCode;
}
if (fufPhoto.HasFile)
{
string FileName = System.IO.Path.GetFileName(fufPhoto.PostedFile.FileName);
string FilePath = "Uploads/" + folderName + "/" + FileName;
bool exists = System.IO.Directory.Exists(Server.MapPath("~/Uploads/" + folderName + "/"));
if (!exists)
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/" + folderName + "/"));
}
fufPhoto.PostedFile.SaveAs(Server.MapPath("~/Uploads/" + folderName + "/" + FileName));
imageUrl = FilePath;
}
if (fufVideo.HasFile)
{
string FileName = System.IO.Path.GetFileName(fufVideo.PostedFile.FileName);
string FilePath = "Uploads/" + folderName + "/" + FileName;
bool exists = System.IO.Directory.Exists(Server.MapPath("~/Uploads/" + folderName + "/"));
if (!exists)
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/" + folderName + "/"));
}
fufVideo.PostedFile.SaveAs(Server.MapPath("~/Uploads/" + folderName + "/" + FileName));
videoUrl = FilePath;
}
但我无法上传视频文件。用于上传视频文件Ext.Net中是否有任何唯一的字段类型?请帮帮我。
答案 0 :(得分:0)
看起来你的代码工作正常。(据我所知,除了uploadfield之外你不需要任何特殊字段)我能够成功上传图像和视频。这是我如何测试它
aspx代码
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:FileUploadField runat="server" ID="fufVideo" LabelWidth="130" FieldLabel="Video Path"></ext:FileUploadField>
<ext:FileUploadField runat="server" ID="fufPhoto" LabelWidth="130" FieldLabel="Title Image Path"></ext:FileUploadField>
<%--<ext:TextField runat="server" ID="txtDisplayOrder" LabelWidth="130" FieldLabel="Display Order" AllowBlank="false"></ext:TextField>--%>
<ext:Checkbox ID="chkOnHomePage" runat="server" LabelWidth="130" FieldLabel="Show On Home Page?"></ext:Checkbox>
<ext:Checkbox ID="chkIsActive" runat="server" LabelWidth="130" FieldLabel="Is Active?"></ext:Checkbox>
<ext:DateMenu ID="dateAdd" runat="server" LabelWidth="90" FieldLabel="Added Date"></ext:DateMenu>
<ext:DatePicker ID="dateExpired" runat="server" LabelWidth="90" FieldLabel="Expired Date"></ext:DatePicker>
<ext:Button runat="server" Text="UploadImageandVideo">
<DirectEvents>
<Click OnEvent="UploadVideoAndImage">
<Confirmation ConfirmRequest="true" Title="Title" Message="Sample Confirmation Message..." />
</Click>
</DirectEvents>
</ext:Button>
</form>
背后的代码
public partial class VideoFileUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void UploadVideoAndImage(object sender, DirectEventArgs e)
{
string videoUrl = "";
string imageUrl = "";
const string folderName = "clientname";
if (fufPhoto.HasFile)
{
string FileName = System.IO.Path.GetFileName(fufPhoto.PostedFile.FileName);
string FilePath = "Uploads/" + folderName + "/" + FileName;
bool exists = System.IO.Directory.Exists(Server.MapPath("~/Uploads/" + folderName + "/"));
if (!exists)
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/" + folderName + "/"));
}
fufPhoto.PostedFile.SaveAs(Server.MapPath("~/Uploads/" + folderName + "/" + FileName));
imageUrl = FilePath;
}
if (fufVideo.HasFile)
{
string FileName = System.IO.Path.GetFileName(fufVideo.PostedFile.FileName);
string FilePath = "Uploads/" + folderName + "/" + FileName;
bool exists = System.IO.Directory.Exists(Server.MapPath("~/Uploads/" + folderName + "/"));
if (!exists)
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/" + folderName + "/"));
}
fufVideo.PostedFile.SaveAs(Server.MapPath("~/Uploads/" + folderName + "/" + FileName));
videoUrl = FilePath;
}
}
}