1

i want to upload multiple pdf files in one file upload control in asp.net and then merg it , this is already done when i pass static path and file name how to do that dynamically my code is here

  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\[email protected]".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;
                }
            }

1 Answer 1

2

You will need to collect values of path in a List<string> and then pass the result to MergeFiles().

I don't quite follow your code (you'll need to clean it up a bit), but what you need is basically this:

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);

Beware of duplicating file names in ~/images, though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.