PdcAttachment.Save

From External Bemet Wiki
Revision as of 12:18, 5 January 2024 by TC (talk | contribs)
Jump to navigation Jump to search

Declaration

Save(FilePath as String) as Boolean

Description

This function will add a new attachment to Bemet.

Notes

This function will work onPrem, or in the cloud with either the Document Repository or Sharepoint.
When saving a new attachment, Bemet will try to find the source file to add to Bemet based on both the Attachment properties and the parameters passed. It will look for the file in the following order:

  1. If the attachment has no filename, but the file has been read using the PdcAttachment.ReadData function, it will use that stream.
  2. If the PdcAttachment.TempFilePath property contains a path, it will use the file at this location
  3. If the FilePath parameter of this function is not empty, it should contain a full path to a file on disk, that file will be used.


When using Sharepoint, if this file already exists for the specific entity you are copying to ( for example calculation 12345 already has a drawing.pdf, and you are uploading another drawing.pdf) then it will overwrite this file in the sharepoint folder.


Code example

Adding a local file to Bemet

Dim calcAttachList As PDCEXT.IPdcAttachmentList = PDC.App.AttachmentList
calcAttachList.ReadFromTableName("DO_CALC", tbCalcNr.Text)

Dim newAttach As PDCEXT.IPdcAttachment = calcAttachList.Add()
newAttach.FileName = "NewFile.pdf"
newAttach.TempFilePath = "C:\AFolder\NewFile.pdf"
newAttach.Save("")


Copying all attachments of a calculation to a sales invoice

Dim calcAttachList As PDCEXT.IPdcAttachmentList = PDC.App.AttachmentList
calcAttachList.ReadFromTableName("DO_CALC", tbCalcNr.Text)

Dim invAttachList As PDCEXT.IPdcAttachmentList = PDC.App.AttachmentList
invAttachList.ReadFromTableName("FACTUUR", tbInvNr.Text)

For attachIndex As Integer = 0 To calcAttachList.Count - 1
    Dim attachment = calcAttachList.Items(attachIndex)

    Dim copyAttachment As PDCEXT.IPdcAttachment = invAttachList.Add
    copyAttachment.FileName = attachment.FileName
    copyAttachment.TempFilePath = attachment.TempFilePath
    copyAttachment.Save("")
Next

</source>