Extjs+C# 实现文件上传
2016-12-21 14:26
309 查看
Extjs 代码
var ImportPanel = new Ext.form.FormPanel({
baseCls: 'x-plain',
frame: false,
// 注意formPanel里面的fileUpload一定要打开
fileUpload: true,
id: 'ImportPanel',
url: 'Excel.aspx?ac=Import',
items: [{
xtype: 'textfield',
// 注意要有以下字段
inputType: 'file',
fieldLabel: '请选择导入文件',
id: 'stationFile',
width: 150,
allowBlank: false
}]
});
var ImportWinFrom = new Ext.Window({
layout: 'fit',
width: 360,
height: 100,
closeAction: 'hide',
title:'导入数据',
plain: true,
items: ImportPanel,
buttons: [{
text: '提交',
formPanel:this.ImportPanel,
handler: function() {
this.formPanel.form.submit({
success: function(form, action) {
Ext.Msg.alert("导入成功", action.result.msg);
mportWinFrom.hide();
},
scope: this,
failure: function(form, action) {
Ext.Msg.alert("导入失败", action.result.msg);
this.parent.SuperSearchWinForm.hide();
}
});
}
}, {
text: '取消',
handler: function() {
ImportWinFrom.hide();
}
}]
});
C#代码
public void UploadFile()
{
// 接收Http发送过来的文件
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile postedFile = files[0];
Hashtable hash = new Hashtable();
JavaScriptSerializer adapter = new JavaScriptSerializer();
string url = "uploadfile/excel/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
try
{
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(url));
}
catch
{
hash.Add("success",false);
hash.Add("msg", "上传附件失败!");
MyResponse(hash);
}
}
var ImportPanel = new Ext.form.FormPanel({
baseCls: 'x-plain',
frame: false,
// 注意formPanel里面的fileUpload一定要打开
fileUpload: true,
id: 'ImportPanel',
url: 'Excel.aspx?ac=Import',
items: [{
xtype: 'textfield',
// 注意要有以下字段
inputType: 'file',
fieldLabel: '请选择导入文件',
id: 'stationFile',
width: 150,
allowBlank: false
}]
});
var ImportWinFrom = new Ext.Window({
layout: 'fit',
width: 360,
height: 100,
closeAction: 'hide',
title:'导入数据',
plain: true,
items: ImportPanel,
buttons: [{
text: '提交',
formPanel:this.ImportPanel,
handler: function() {
this.formPanel.form.submit({
success: function(form, action) {
Ext.Msg.alert("导入成功", action.result.msg);
mportWinFrom.hide();
},
scope: this,
failure: function(form, action) {
Ext.Msg.alert("导入失败", action.result.msg);
this.parent.SuperSearchWinForm.hide();
}
});
}
}, {
text: '取消',
handler: function() {
ImportWinFrom.hide();
}
}]
});
C#代码
public void UploadFile()
{
// 接收Http发送过来的文件
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile postedFile = files[0];
Hashtable hash = new Hashtable();
JavaScriptSerializer adapter = new JavaScriptSerializer();
string url = "uploadfile/excel/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
try
{
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(url));
}
catch
{
hash.Add("success",false);
hash.Add("msg", "上传附件失败!");
MyResponse(hash);
}
}
相关文章推荐
- C#上传文件的一个实现
- ASP.NET 2.0(C#)实现多文件上传
- FCKeditor实现上传分月目录和文件重命名(C#)
- C#实现Web文件上传的两种方法
- (C#)实现多文件上传
- 用C# 实现Web文件的上传
- C#实现Web文件上传的两种方法
- C#代码实现上传文件到SharePoint文档库
- 文件上传的实现(C#)
- asp.net(c#)实现文件上传
- 用C#实现Web文件的上传
- C#上传文件的一个实现
- 使用IIS作文件服务,使用C#实现上传删除
- FCKeditor实现上传分月目录和文件重命名(C#)
- ASP.NET(C#)实现一次性上传多张图片(多个文件)
- c#实现按日期命名上传文件代码
- ASP.NET(C#)实现一次性上传多张图片(多个文件)
- C#实现Web文件上传的两种方法
- ASP.NET(C#)实现一次性上传多张图片(多个文件)
- C#实现Web文件上传的两种方法