一个页面中好几个fileupload
其中最后一个是用js代码生成的,可以无限生成多个<input type='file' id="myFile" />
我用一个多文件上传函数只负责传这些js生成的file,其余的file用单文件上传函数来上传(别问为什么,就得这么来)
多文件上传函数只接收httppostfiles参数,但是最后麻烦了,我得从httpfilecollection里面检索出来那些以"myFile"命名的files来啊
于是我
httpfilecollection files=request.files;
httpfilecollection myFiles=files.get("myFile");
告诉我httpfilecollection <-> httppostfile不能隐式转换,那我该怎么办??
其中最后一个是用js代码生成的,可以无限生成多个<input type='file' id="myFile" />
我用一个多文件上传函数只负责传这些js生成的file,其余的file用单文件上传函数来上传(别问为什么,就得这么来)
多文件上传函数只接收httppostfiles参数,但是最后麻烦了,我得从httpfilecollection里面检索出来那些以"myFile"命名的files来啊
于是我
httpfilecollection files=request.files;
httpfilecollection myFiles=files.get("myFile");
告诉我httpfilecollection <-> httppostfile不能隐式转换,那我该怎么办??
是的话,<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="upLoadFiles.aspx.cs" Inherits="NetSamples.upLoadFiles" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<div>
<input id="File1" type="file" name="File1" />
<br />
<input id="File2" type="file" name="File2" />
<br />
<asp:Button
ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace NetSamples
{
public partial class upLoadFiles : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
if (Request.Files != null)
{
HttpFileCollection files = Request.Files;
string fileName;
for(int i = 0;i < files.Count;i++)
{
if (files[i].ContentLength <= 0)
{
continue;
}
fileName = Path.GetFileName(files[i].FileName);
files[i].SaveAs(Request.MapPath(@"../files/" + fileName));
}
}
}
}
}获取文件扩展名:System.IO.Path.GetExtension(path);
{
var str = ' <input type="file" name="fileSuccess" class="input_1" runat="server" style="width: 300px"/><BR>'
document.getElementById('successFiles').insertAdjacentHTML("beforeBegin",str)
}其余的几个不是,我只想用mutiFileUpload上传这些js生成的files
所以,我需要从request.files截取一部分名字是fileSuccess的httppostfile出来,并传递给我的mutiFileUpload函数,谢谢
如何从HttpFileCollection集合中得到具有相同key名称的所有httpPostFile对象