C# 如何获取阵列中的多个文件路径
我想在asp.net的一个文件上载控件中上载多个pdf文件,然后对其进行merg, 当我传递静态路径和文件名时,这已经完成了 如何动态地做到这一点 我的密码在这里C# 如何获取阵列中的多个文件路径,c#,asp.net,c#-4.0,C#,Asp.net,C# 4.0,我想在asp.net的一个文件上载控件中上载多个pdf文件,然后对其进行merg, 当我传递静态路径和文件名时,这已经完成了 如何动态地做到这一点 我的密码在这里 if (FileUpload1.HasFile) { try { HttpFileCollection uploadedVideoFiles = Request.Files;
if (FileUpload1.HasFile)
{
try
{
HttpFileCollection uploadedVideoFiles = Request.Files;
// Get the HttpFileCollection
for (int i = 0; i < uploadedVideoFiles.Count; i++)
{
HttpPostedFile hpfiles = uploadedVideoFiles[i];
string fname = Path.GetFileName(hpfiles.FileName);
if (hpfiles.ContentLength > 0)
{
hpfiles.SaveAs(Server.MapPath("~/Images/") + Path.GetFileName(hpfiles.FileName));
hpfiles.SaveAs(Server.MapPath(Path.Combine(@"~/Images/", fname)));
string filepath = Server.MapPath(@"~/Images/");
string path = filepath + fname;
}
}
String[] files = @"C:\ENROLLDOCS\A1.pdf,C:\ENROLLDOCS\A@.pdf".Split(',');
MergeFiles(@"C:\ENROLLDOCS\New1.pdf", files);// merg is a method which merg 2 or more than 2 documents
}
catch (Exception ex)
{
Label1.Text = "The file could not be uploaded. The following error occured: " + ex.Message;
}
}
if(FileUpload1.HasFile)
{
尝试
{
HttpFileCollection uploadedVideoFiles=请求.Files;
//获取HttpFileCollection
对于(int i=0;i0)
{
hpfiles.SaveAs(Server.MapPath(“~/Images/”)+Path.GetFileName(hpfiles.FileName));
hpfiles.SaveAs(Server.MapPath(Path.Combine(@“~/Images/”,fname));
字符串filepath=Server.MapPath(@“~/Images/”);
字符串路径=文件路径+fname;
}
}
字符串[]文件=@“C:\ENROLLDOCS\A1.pdf,C:\ENROLLDOCS\A@.pdf“.Split(“,”);
MergeFiles(@“C:\ENROLLDOCS\New1.pdf”,files);//merg是一种方法,用于合并2个或多个文档
}
捕获(例外情况除外)
{
Label1.Text=“无法上载文件。出现以下错误:“+ex.Message;
}
}
您需要在列表中收集路径的值,然后将结果传递到合并文件()
我不太了解您的代码(您需要清理一下),但您需要的基本上是:
var fileNames =
uploadedVideoFiles.
Select(uvf => {
var fileName = Path.GetFileName(hpfiles.FileName);
var destinatonPath = Path.Combine(Server.MapPath("~/images"), fileName);
uvf.SaveAs(destinatonPath);
return destinationPath;
}).
ToArray();
MergeFiles(@"C:\ENROLLDOCS\New1.pdf", fileNames);
不过,要小心在~/images
中复制文件名