In the code from the server I get the scanned image and from it I get an array of bytes and the image should be saved in the database. Here is the code to save.

try { UploadFileMaintenance upl = PXGraph.CreateInstance<UploadFileMaintenance>(); PX.SM.FileInfo fileinfo = new PX.SM.FileInfo(@"ShipmentEntry\", null, arr); if (upl.SaveFile(fileinfo, FileExistsAction.CreateVersion)) { if (fileinfo.UID.HasValue) { PXNoteAttribute.SetFileNotes(this.Base.Caches["SOShipment"], (SOShipment)(this.Base.Caches["SOShipment"].Current), fileinfo.UID.Value); this.Base.Save.Press(); } } } catch (PXException ex) { /// } 

on this line if (upl.SaveFile(fileinfo, FileExistsAction.CreateVersion)) I get this exception File type is not allowed . The code works in the AcuamticaERP system AcuamticaERP

  • upl.SaveFile (...) is what? there you need to look for an error. - rdorn
  • It seems to be quite a clear exception. File type is not supported. For example, you can add .jpg , and you put .pdf there. - Denis Bubnov
  • 3
    in any case, nobody will be able to reproduce this error except for you, all the classes used in the given code example are self-written, even the seemingly familiar FileInfo (not present in the standard constructor). So either you will give a reproducible example of your problem, or we will wonder: what do you prefer? I'm on a crystal ball for example. - rdorn
  • @rdorn this code is written by Acumatica so the non-standard functions for C# are all in the Acumatica framework - Vardan Vardanyan
  • @DenisBubnov and how to convert an array of bytes to a .jpg file? - Vardan Vardanyan

1 answer 1

I suspect that you have incorrectly initialized fileinfo and you do not have the file name itself and its permission. Most likely the reason for the exception in this line:

  PX.SM.FileInfo fileinfo = new PX.SM.FileInfo(@"ShipmentEntry\", null, arr); 

I found this here with your colleagues:

  PX.SM.FileInfo fileinfo = new PX.SM.FileInfo("case.pdf", null, data); 
  • Yes, I already found thanks for the review. Here is my version of PX.SM.FileInfo fileinfo = new PX.SM.FileInfo(@"SOShipmentEntry\Image_"+DateTime.Now.ToShortDateString()+"_"+DateTime.Now.ToShortTimeString()+".png", null, arr); here it is rather important to specify not the name of the file but the type in my cases .png - Vardan Vardanyan