[英]Extjs File Upload with C#
我知道xtype:filefield的工作原理,并且我也意识到文件上传不使用常规的ajax方法来读取和写入数据库数据。
我可以正常设置文件字段,当我单击浏览按钮时,可以选择所需的文件。
this.fp = Ext.create('Ext.form.Panel', {
scope: this,
width: 200,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
items: [
{
xtype: 'filefield'
}
],
buttons: [
{ text: 'Upload',
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url: 'Upload.aspx',
waitMsg: 'Uploading your file...',
success: function (form, action) {
alert("OK:" + action.result.message);
},
failure: function (form, action) {
alert("Error:" + action.result.message);
}
});
}
}
}
]
});
单击上传按钮后发生的问题是问题...如何使用c#将文件上传到服务器端...(sql db)...
我尝试使用upload.aspx.cs创建一个upload.aspx页面,并且这样做只是为了看看它是否有效...
public partial class Upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
if (context.Request.Files.Count > 0)
{
BinaryReader file = new BinaryReader(context.Request.Files[0].InputStream);
string line;
while ((line = file.ReadString()) != null)
{
// sql connection?
}
}
// prepare response
MessageOb result = new MessageOb();
result.success = true;
result.message = "Success";
}
}
但是我得到这个错误
Ext.Error: You're trying to decode an invalid JSON String:
有文件记录在哪里,我可以看到从客户端的extjs和服务器端的c#将文件上传到sql db的通常步骤...或者如果有人可以向我展示它的完成方式,我将不胜感激
问题可能与您如何从上传表单提交中返回数据有关。 Ext.JS要求响应为JSON或XML,我将确认您没有返回html文档。
我认为MessageOb可以通过某种方式处理此问题...也许吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.