.NET Web方法文件上传
可以使用 FileUpload Control 和 WebMethod 上传文件吗?
我想避免使用 UpdatePanel 和 ScriptManagers。
我该怎么做呢? Web 方法会是什么样的参数?有例子吗?
谢谢!
is possible to upload a file by using FileUpload Control and WebMethod?
I would like to avoid the UpdatePanel and ScriptManagers.
How can I do it? What kind of parameter the Web Method would be? Is there any example?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法找到您使用
WebMethod
询问的解决方案,因此我提出了使用HTTPHandler
或更广为人知的ASPX
控件/页面的替代解决方案。为了实现你想要的,我使用Valums File Upload,有很多替代方案,但这是我发现非常适合我的情况的一个。您可以在此处找到更多信息、文档并下载 javascript 代码:
http://valums.com/ajax-upload/
该代码还给出了如何在服务器端处理请求的示例,但是,它不包含.net中的代码示例,所以我找到了这个项目。
http://www.codeproject.com/KB/aspnet/AspNetHandlerAjaxUpload.aspx
它使用Valums File Upload并在服务器端使用.Net C#处理文件上传请求。
总而言之,以下是如何在客户端使用Valums 文件上传:
使用此代码创建文件上传控件
使用此 javascript 代码设置文件上传控件
<前><代码>$(函数 () {
var uploader = new qq.FileUploader({
元素: document.getElementById('divFileUpload'),
操作:'文件上传.ashx',
onComplete:函数(id,文件名,responseJSON){
if (responseJSON.Success) {
警报(“成功”);
}
}
});
});
在服务器端:
示例代码
非常重要,向客户端返回JSON类型。
有关如何处理客户端请求的更多详细信息,请参阅上面的 URL。
所有功劳均归于 Andrew Valums 的 Valums 文件上传 和 Syed BASHAR 的使用 Valums 文件上传的 .Net 服务器代码< /em>.
I could not find solution you asked using
WebMethod
so I come up with alternative solution which is usingHTTPHandler
or better known asASPX
control/page.To achieve what you wanted, I use Valums File Upload, there are many alternative out there but this is the one that I found very suitable for my case. You can find more information, documentation and download the javascript code here:
http://valums.com/ajax-upload/
The code also give example of how to handle the request in server side however, it doesn't include code example in .net so I found this project.
http://www.codeproject.com/KB/aspnet/AspNetHandlerAjaxUpload.aspx
Which use Valums File Upload and handle the file upload request using .Net C# on server side.
To summarize, here is how you use the Valums File Upload on client side:
Use this code for creating file upload control
Use this javascript code to setup the file upload control
On the server side:
Sample code
Very important, return JSON type to the client.
For more detail about how to handle the request from client side, please refer to the URL above.
All credits go to the Andrew Valums for the Valums File Upload and Syed BASHAR for the .Net server code using Valums File Upload.