2015-08-28 32 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

相關問題