Saving a file in FILES

Viewed 187

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.

1 Answers

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);
                        
                    }

                }
Related