ASP.Net 从 jQuery 选择多个文件后上传

发布于 2024-07-10 19:02:24 字数 330 浏览 15 评论 0原文

我使用了 jQuery 多文件上传控件 [来自 fyneworks 的 MultiFile http: //www.fyneworks.com/jquery/multiple-file-upload/#tab-Overview ] 收集一些文件名,但无法弄清楚如何将它们上传到服务器上。

标准的 asp:FileUpload 控件似乎只允许单个文件,我不想使用 swfupload 控件,只是普通的旧 aspx。

I have used a jQuery multiple file upload control [ MultiFile from fyneworks http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Overview ] to collect some filenames but can't work out how to upload them on the server.

The standard asp:FileUpload control only seems to allow single files and I don't want to use the swfupload control, just plain old aspx.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

世界等同你 2024-07-17 19:02:24

(我自己回答了这个问题,我只是在通过 goole 或 SO 找到答案时遇到问题,它似乎很有用......)

这段代码适用于我需要的东西,感谢 Suprotim Agarwal http://www.dotnetcurry.com/ShowArticle.aspx?ID=68

使用合适的 jQuery 倍数选择文件后上传控件(例如来自 fyneworks 的 MultiFile http://www.fyneworks.com /jquery/multiple-file-upload/#tab-Overview)
并且已经点击了提交按钮,在aspx文件中调用以下代码

HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
    HttpPostedFile hpf = hfc[i];
    if (hpf.ContentLength > 0)
    {               
        hpf.SaveAs(Server.MapPath("Uploads") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
    }
}   

(I have answered this question myself, I just had problems finding the answer via goole or SO and it seems useful ...)

This code works for what I need, thanks to Suprotim Agarwal http://www.dotnetcurry.com/ShowArticle.aspx?ID=68

Once the files have been chosen using a suitable jQuery multiple upload control (eg MultiFile from fyneworks http://www.fyneworks.com/jquery/multiple-file-upload/#tab-Overview)
and the submit button has been clicked, call the following code in the aspx file

HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
    HttpPostedFile hpf = hfc[i];
    if (hpf.ContentLength > 0)
    {               
        hpf.SaveAs(Server.MapPath("Uploads") + "\\" + System.IO.Path.GetFileName(hpf.FileName));
    }
}   
み青杉依旧 2024-07-17 19:02:24

HttpFileCollection 上传 = HttpContext.Current.Request.Files;

for (int i = 0; i < uploads.Count; i++)
{

        HttpPostedFile upload = (HttpPostedFile)uploads[i];

HttpFileCollection uploads = HttpContext.Current.Request.Files;

for (int i = 0; i < uploads.Count; i++)
{

        HttpPostedFile upload = (HttpPostedFile)uploads[i];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文