日期:2014-05-19  浏览次数:20854 次

怎么才能同时上传多个文件到服务器上呢?
怎么才能同时上传多个文件到服务器上呢?
我用File一次就能传一个....

------解决方案--------------------
我以前写的一个函数,将文件另外保存,且可以需要的数据,如名字,大小.
private void UploadFile ()
{
try
{
bool ReturnValue = false;
int count=Request.Files.Count;
//上传原始文件完全路径
System.Collections.ArrayList SourceFiles = new System.Collections.ArrayList();
//上传后保存文件完全路径
System.Collections.ArrayList TargetFiles = new System.Collections.ArrayList();
//1.确定是否选择了文件
for (int i=0;i <count;i++)
{
HttpPostedFile hif = Request.Files[i];
if ( hif.ContentLength > 0 )
{
SourceFiles.Add( hif.FileName );
ReturnValue = true;
}
}
if ( !ReturnValue )
{
Response.Write( " <script> alert( '请选择上传文件! '); </script> ");
return;
}

//2.确定上传路径,写在配置文件中
string savePath = System.Configuration.ConfigurationSettings.
AppSettings[ "QfcFileUploadPath "].ToString();
savePath = this.Server.MapPath( savePath );

//3.组合上传文件的路径和需要保存的路径
for ( int i = 0; i < SourceFiles.Count ; i++ )
{
char[] de={ '\\ '};
string []tempstr = SourceFiles[ i ].ToString().Split(de);
string fileName = tempstr [tempstr.Length-1];
TargetFiles.Add( savePath + @ "\ " + fileName );
}

//4.确认路径是否存在
if ( !System.IO.Directory.Exists( savePath ) )
System.IO.Directory.CreateDirectory( savePath );

//5.上传文件操作
int index = 0;
for (int i=0;i <count;i++)
{
HttpPostedFile hif = Request.Files[i];
if ( hif.ContentLength > 0 )
{
hif.SaveAs( TargetFiles[ index ].ToString() );
index++;
}
}
//6.可以把需要的数据保存到数据库
}
catch
{
//操作
}
}

------解决方案--------------------
上传到一个服务器,然后使用allwayssync等同步软件同步文件
------解决方案--------------------
多用几个file不行吗?
------解决方案--------------------
多用几个上传的类的实例就行了
------解决方案--------------------
新人学习中,请勿打搅,看结果!!!!嘿嘿