title: How to split wav file into two or more parts using c#
body: <p>Here the below code for splitting a large 600mb audio wav file into two parts inside button click event..</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
  string inputFile = Server.MapPath("~/inputPath/BetterFasterCheaperGovt-HD+720p.wav"); // Substitute this with your Input File 
      FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
      int numberOfFiles = 2;
      int sizeOfEachFile = (int)Math.Ceiling((double)fs.Length / numberOfFiles);
      for (int i = 1; i &lt;= numberOfFiles; i++)
      {
          string baseFileName = Path.GetFileNameWithoutExtension(inputFile);
          string extension = Path.GetExtension(inputFile);
          FileStream outputFile = new FileStream(Path.GetDirectoryName(inputFile) + "\\" + baseFileName + "_" + i.ToString().PadLeft(3, Convert.ToChar("0")) + extension, FileMode.Create, FileAccess.Write);
          int bytesRead = 0;
          byte[] buffer = new byte[sizeOfEachFile];
          if ((bytesRead = fs.Read(buffer, 0, sizeOfEachFile)) &gt; 0)
          {
              outputFile.Write(buffer, 0, bytesRead);
          }
          outputFile.Close();
      }
      fs.Close();
      ClientScript.RegisterStartupScript(this.GetType(), "popup", "alert('success');", true);
  }
  </code></pre>
  
  <p>it splits successfully into two file each of same size i.e., 300mb but the 
  part1.wmv is 300mb showing length as 1hr 16min
  part2.wmv is 300mb length is 0.</p>
  
  <p>means there is no audio in part2.wav only blank corrupted file is created.</p>
  
  <p>please help me out with fixing the issue.
  Thanks!!</p>