title: BadRequest unexpected token ILLEGAL when downloading ZIP file
body: <p>I am working on an asp.net application using <strong>Ext.Net</strong> for my UI and Ajax calls (DirectMethods). I am trying to download a zip file on the server using DotNetZip. There are two parts to the download process:</p>
  
  <ul>
  <li><p>Part 1: First invoke method <strong>ExportXML</strong> to export in-memory XMLs to physical XML files on the server in a folder.</p></li>
  <li><p>Part 2: On success of ExportXML method invoke <strong>DownloadZipFile</strong>. This method uses DotNetZip to zip these XML files and call Save method on the ZipFile object to invoke download on the browser.</p></li>
  </ul>
  
  <p><em>Client side Ext.Net code</em></p>
  
  <pre><code>Ext.net.DirectMethods.ExportXML(ids, {
                  success: function (zipID) {
                      Ext.net.DirectMethods.DownloadZipFile(zipID);
                  },
                  eventMask: {
                      showMask: true,
                      msg: "Creating XML files... This may take some time..."
                  }
              });
  </code></pre>
  
  <p><em>Server side DirectMethods</em></p>
  
  <pre><code>[DirectMethod]
      public void DownloadZipFile(string randomFolderName)
      {
          var zippedXMLFiles = new ZipFile();
          var filePath = System.IO.Path.Combine(m_baseExportFolder, randomFolderName);
  
          Response.AddHeader("Content-Disposition", "attachment; filename=massExportXML.zip");
          Response.ContentType = "application/zip";
          var xmlDir = new DirectoryInfo(filePath);
          foreach (var fileInfo in xmlDir.GetFiles())
          {
              zippedXMLFiles.AddFile(fileInfo.FullName, string.Empty);
          }
  
          zippedXMLFiles.Save(Response.OutputStream);
      }
  
      [DirectMethod]
  
  
      public string ExportXML(string[] kCodes)
      {
          var folderID = System.IO.Path.GetRandomFileName();
          var folderPath = System.IO.Path.Combine(m_baseExportFolder, folderID);
          System.IO.Directory.CreateDirectory(folderPath);
  
          foreach (var kCode in kCodes)
          {
              GenerateXML(Convert.ToInt32(kCode), folderPath);
          }
  
          return folderID;
      }
  </code></pre>
  
  <p><strong><em>GenerateXML</strong> is the method which converts the in-memory XML to the physical XML file.</em></p>
  
  <p>My code runs successfully to create the zip file and add the zip files, however, on the browser I see </p>
  
  <p><img src="https://i.stack.imgur.com/rC1m6.png" alt="Error displayed when downloading the zip file"></p>
  
  <p>and HTTP Response Code as 200 (this means no problems with the request). I am so confused why this does not work.</p>
  
  <p>Please help!</p>
  
  <p>Thanks,
  Vaibinewbee</p>