1

I want to save generated text file in 'FILES' section on the Acumatica page, by clicking on the action 'Save File Up There'. This is my current code for generating the text file:

    string[] lines = { fileLine1, fileLine2, fileLine3 };
    File.WriteAllLines(path, lines);

This just generates a text file in the specified path on my machine.

Screenshot of the Batch Payment Screen

Batch Payments Screen

Any help would be appreciated.

Stumped
  • 21
  • 4

1 Answers1

0

I would try something like the below where 'message' is a string.

                using (MemoryStream stream = new MemoryStream())
                {
                    stream.Write(Encoding.UTF8.GetBytes(message), 0, message.Length);

                    string path = "MyFile.txt"; 
                    PX.SM.FileInfo info = new PX.SM.FileInfo(path, null, stream.ToArray());

                    //Attach file to Doc
                    info.Comment = "message generated on " + DateTime.Now.ToShortDateString();
                    UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();

                    //Save file to acumatica
                    if (upload.SaveFile(info, FileExistsAction.CreateVersion))
                    {
                        //Create connection to the Batch
                        PXNoteAttribute.SetFileNotes(mysetup.connection.Cache, conn, info.UID.Value);
                        
                    }

                }
Patrick Chen
  • 1,028
  • 1
  • 6
  • 8
  • Everything looks right so far, but I just can't figure out what you meant with 'conn' in 'PXNoteAttribute.SetFileNotes(mysetup.connection.Cache, conn, info.UID.Value);'. Could you please elaborate. – Stumped Mar 25 '21 at 14:39
  • Conn is an object of the type contained in mysetup.connection.cache – Patrick Chen Mar 25 '21 at 17:28
  • Thanks for the help @Patrick Chen, got it working on my end. – Stumped Apr 08 '21 at 10:59