0

I want to merge two files and save it is as new file.

e.g

a1,a2 new a3

...and then upload that file which i have merge which is a3.

I mean I am saving a file in a folder , i want when i save , i get exactly that f filename as well filepath.

here is my code.

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;
           }
      }
 }
Razim Khan
  • 337
  • 5
  • 23
  • The code sample suggest these are video files (unspecified format), then the MergeFiles function is operating on PDF document files... The answer to the question "how to merge the files" will vary by the type of file. In general... to do a merge from an upload you will save each file to memory (or disk), then merge them using whatever process is required for the file type, then save the result. Note that the merging happens after the source files are uploaded. Update your question and clarify to get a full answer :) – Ty H. Aug 28 '15 at 05:44
  • these are pdf file ,i mistakenly name it uploadvideofiles, its name is uploadpdffiles – Razim Khan Aug 28 '15 at 05:51
  • check it now its clear ? @TyH. – Razim Khan Aug 28 '15 at 05:53
  • Can you post the code of the MergeFiles function? – Ruben Aguilar Aug 28 '15 at 06:30

1 Answers1

1

iTextSharp is a C# PDF library that can read and write PDF's based on the iText library, it's free for open source... paid for commercial use. Here is an existing example of how to merge two PDF's using their library, you can easily adapt it to the file upload scenario.

Merging multiple PDFs using iTextSharp in c#.net

Community
  • 1
  • 1
Ty H.
  • 905
  • 8
  • 8