简体   繁体   English

如何获取FileName,FilePath以将其存储在Variabl中,然后将该文件上传到asp.net

[英]how to get FileName, FilePath to Store it in a Variabl and then upload that file in asp.net

I want to merge two files and save it is as new file. 我想合并两个文件并将其保存为新文件。

eg 例如

a1,a2 new a3 a1,a2新a3

...and then upload that file which i have merge which is a3 . ...然后上传我已合并为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. 我的意思是我正在将文件保存在文件夹中,我想在保存时得到那个f文件名以及文件路径。

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

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. iTextSharp是一个C#PDF库,可以基于iText库读取和写入PDF,它是免费的开放源代码...付费用于商业用途。 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. 这是一个现有示例,说明如何使用它们的库合并两个PDF,您可以轻松地使其适应文件上传方案。

Merging multiple PDFs using iTextSharp in c#.net 在c#.net中使用iTextSharp合并多个PDF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM