Skip to content

Instantly share code, notes, and snippets.

@yuriycto
Created April 21, 2023 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriycto/46eb4be2a9e26b0c9fc5e25a29383641 to your computer and use it in GitHub Desktop.
Save yuriycto/46eb4be2a9e26b0c9fc5e25a29383641 to your computer and use it in GitHub Desktop.
AttachFile.cs
public void AttachFile()
{
//Convert your file into BIN format
byte[] fileInBytes = Encoding.UTF8.GetBytes("My best ever file.");
// Generate info about the file
var fileInfo = new PX.SM.FileInfo(Guid.NewGuid(), "OneFile.txt", null, fileInBytes);
// Save file to database
var uploadFileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
uploadFileGraph.SaveFile(oneFileInfo, FileExistsAction.CreateVersion);
// Attach file to the dedicated table
PXNoteAttribute.SetFileNotes(Base.Caches[typeof(DAC)], aRow, fileInfo.UID.Value); uploadFileGraph.Persist();
this.Persist();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment