title: Generate Text File Upon Button Action and Save to local Drive using Acumatica
body: <p>I am trying to generate a <strong>text file</strong> on an Action Button, with contents of a dataview created in a Graph Class and Save the file in my Local Drive. But i am unable to do it.</p>
  
  <p>Please help me with the file generation...Thanks</p>
  
  <p>I AM USING Acumatica Version 2019R2 (v 19.203.0042)</p>
  
  <p>MY CODE GOES HERE...</p>
  
  <pre><code>public PXSelect&lt;MayBankGIRO&gt; Document; //this is my dataview
  public PXAction&lt;MayBankGiroFilter&gt; createTextFile;
          [PXUIField(DisplayName = "Create Text File")]
          [PXButton()]
          public virtual IEnumerable CreateTextFile(PXAdapter adapter)
          {
              string filepath = "C:\\Subhashish Dawn";
              System.IO.StreamWriter sw = new System.IO.StreamWriter(filepath);
              MayBankGIRO giroObject = this.Document.Current;
              List&lt;object&gt; myListObject = new List&lt;object&gt; { };
              FixedLengthFile flatFile = new FixedLengthFile();
              foreach (MayBankGIRO dacRecord in this.Document.Select())
              {
                  if (giroObject.ReordType == "00")
                  {
                      myListObject.Add(dacRecord.ReordType + "|" + dacRecord.CorporateID + "|" + dacRecord.ClientBatchID + "|");
                  }
                  else
                  {
                      myListObject.Add(dacRecord.ReordType + "|" + dacRecord.CorporateID + "|" + dacRecord.ClientBatchID + "|" + dacRecord.Country + "|");
                      string data = dacRecord.ReordType;
  
                  }
  
                  this.Document.Update(dacRecord);
              }
              flatFile.WriteToFile(myListObject, sw); 
  
              sw.Flush();
              sw.FlushAsync();
  
              string path = "DAWN" + ".txt";
              PX.SM.FileInfo file = new PX.SM.FileInfo(Guid.NewGuid(), path, null, System.Text.Encoding.UTF8.GetBytes(**path**)); // what shall i substitite in place of  **path**
              throw new PXRedirectToFileException(file, true);
  }
  ``````````````````````````````````````````````````````
  Can anyone please specify what changes in have to make in the above code.
  
  
  </code></pre>