title: How to combine multiple chunked zip files into single file using C#.Net?
body: <p>I have to upload huge file using c# and MVC , here i can able to chunk the big file into several files using <strong>j-query by slice(Splitting the files)</strong> function and uploaded to server location. but i'm <strong>not able to open the combined(merged) files</strong> again which is coded through c#.net. </p>
  
  <p>Mainly <strong>zip,.7z files not opened properly</strong> , rest of another files like <strong>.mp3, .doc,.PDF , etc are opened in proper way.</strong> </p>
  
  <p>Here i attached the c# code</p>
  
  <p><strong>Method 1:</strong></p>
  
  <pre><code>private void JoinFiles(string FolderInputPath, string FileOutputPath)
  {    
      DirectoryInfo diSource = new DirectoryInfo(FolderInputPath);
  
      FileStream fsSource = new FileStream(FileOutputPath, FileMode.Append);
  
              foreach (FileInfo fiPart in diSource.GetFiles(@"*."))
              {
                  Byte[] bytePart = System.IO.File.ReadAllBytes(fiPart.FullName);
                  fsSource.Write(bytePart, 0, bytePart.Length);
              }
              fsSource.Close();
   }
  </code></pre>
  
  <p><strong>Method 2:</strong></p>
  
  <pre><code>{
  string[] tmpfiles = Directory.GetFiles(Server.MapPath("~/App_Data/Uploads/Tamp"), "*.");
  
                  FileStream outPutFile = null;
                  string PrevFileName = "";
  
                  foreach (string tempFile in tmpfiles)
                  {
                      //string fileName = Path.GetFileNameWithoutExtension(tempFile);
                      string baseFileName = fileName.Substring(0, fileName.IndexOf(Convert.ToChar(".")));
                      string extension = Path.GetExtension(fileName);
  
                      if (!PrevFileName.Equals(baseFileName))
                      {
                          if (outPutFile != null)
                          {
                              outPutFile.Flush();
                              outPutFile.Close();
                          }
                          outPutFile = new FileStream(Server.MapPath("~/App_Data/Uploads/Tamp") + "\\" + baseFileName + extension, FileMode.OpenOrCreate, FileAccess.Write);
                      }
  
                      int bytesRead = 0;
                      byte[] buffer = new byte[1024];
                      FileStream inputTempFile = new FileStream(tempFile, FileMode.OpenOrCreate, FileAccess.Read);
  
                      while ((bytesRead = inputTempFile.Read(buffer, 0, 1024)) &gt; 0)
                          outPutFile.Write(buffer, 0, bytesRead);
  
                      inputTempFile.Close();
                      System.IO.File.Delete(tempFile);
                      PrevFileName = baseFileName;
  
                  }
  
                  outPutFile.Close();
  }
  </code></pre>