[Ext.Net] FileUploadField使用
前台
<ext:FileUploadField ID="FileUploadField" runat="server" FieldLabel="上傳附件" LabelAlign="Right"
ButtonText="瀏覽" Icon="Attach" />
<ext:Button ID="Upload" runat="server" Text="上傳" Icon="EjectGreen">
<DirectEvents>
<Click OnEvent="btnUploadFile">
</Click>
</DirectEvents>
</ext:Button>
後台C#
protected void btnUploadFile(object sender, DirectEventArgs e)
{
if (this.FileUploadField.HasFile)
{
string FileName = Path.GetFileName(this.FileUploadField.PostedFile.FileName);
string newName = DateTime.Now.ToString(@"yyyyMMddHHmmss") + "_" + FileName;
string savePath = Page.Server.MapPath("`/UploadFile/" + newName);
if(!Directory.Exists(Path.GetDirectoryName(savePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
}
this.FileUploadField.PostedFile.SaveAs(savePath);
}
else
{
X.Msg.Alert("提示訊息", "請選擇需要上傳的文件").Show();
}
}
參考網址:
留言
張貼留言
歡迎留言