2015-08-28 41 views
0

我想合并两个文件,并保存它是作为新的文件。如何获取文件名,文件路径来存放它在Variabl,然后上传该文件在asp.net

e.g

A1,A2新A3

...然后上传那个文件我已经合并,这是A3

我的意思是,我的文件夹中保存文件,我希望当我保存,我得到完全使f文件名和文件路径。

这是我的代码。

protected void Button1_Click(object sender, EventArgs e) 
{ 
    string fname = ""; 
    if (txtFile.HasFile) 
    { 
      try 
      { 
       HttpFileCollection uploadedFiles = Request.Files; 

       // Get the HttpFileCollection 
       string[] filespath = new string[15]; 
       for (int i = 0; i < uploadedFiles.Count; i++) 
       { 
        HttpPostedFile hpfiles = uploadedFiles[i]; 
        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; 
         filespath[i] = path; 
        } 
       } 

       // MergeFiles(@"C:\ENROLLDOCS\New Document.pdf"+DateTime.Now.ToFileTime(), filespath); 
       MergeFiles(@"D:\Razim\MedFlow\tempp\New Document.pdf" + " " + DateTime.Now.ToFileTime() + ".pdf", filespath); 
       // now i want to get the filename and filepath which i have merged and saved, for uploading.      

      } 
      catch (Exception ex) 
      { 
       Label1.Text = "The file could not be uploaded. The following error occured: " + ex.Message; 
      } 
     } 
} 
+0

的代码示例表明这些视频文件(未指定的格式),那么MergeFiles功能在PDF文档的文件操作...回答这个问题:“如何合并文件”将被改变文件类型。一般来说...要从上传中进行合并,您需要将每个文件保存到内存(或磁盘),然后使用文件类型所需的任何进程合并它们,然后保存结果。请注意,合并发生在源文件上传后。更新你的问题和澄清,以获得一个完整的答案:) –

+0

这些都是pdf文件,我错误地将其命名为uploadvideofiles,它的名字是uploadpdffiles –

+0

检查它现在它清楚了吗? @TyH。 –

回答

1

iTextSharp的是C#PDF库,可以读写PDF的基础上,iText库,它是免费的开源...支付用于商业用途。以下是如何使用库合并两个PDF的现有示例,您可以轻松地将其适用于文件上传场景。

Merging multiple PDFs using iTextSharp in c#.net