PdcAttachment.Save: Difference between revisions

From External Bemet Wiki
Jump to navigation Jump to search
Created page with "== Declaration == Save(FilePath as String) as Boolean == Description == This function saves the attachment in Bemet == Notes == == Code example == This example adds a new..."
 
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:


== Description ==
== Description ==
This function saves the attachment in Bemet  
This function will add a new attachment to Bemet.


== Notes ==
== Notes ==
This function will work onPrem, or in the cloud with either the Document Repository or Sharepoint.<br>
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:
# If the attachment has no filename, but the file has been read using the [[PdcAttachment.ReadData]] function, it will use that stream.
# If the [[PdcAttachment.TempFilePath]] property contains a path, it will use the file at this location
# 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.
<br>
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 ==
== Code example ==
This example adds a new attachment to calculationnumber 12345
Adding a local file to Bemet<br>
<source lang="vb.Net">
<source lang="vb.Net">
Dim attachmentlist As PDCEXT.PdcAttachmentList = PDC.App.AttachmentList
Dim calcAttachList As PDCEXT.IPdcAttachmentList = PDC.App.AttachmentList
if attachmentlist.Read("DO_CALC", "", "12345") then
calcAttachList.ReadFromTableName("DO_CALC", tbCalcNr.Text)
  dim attachment = attachmentlist.add
 
  attachment.filename = "C:\test.txt"
Dim newAttach As PDCEXT.IPdcAttachment = calcAttachList.Add()
  attachment.Save
newAttach.FileName = "NewFile.pdf"
end if
newAttach.TempFilePath = "C:\AFolder\NewFile.pdf"
newAttach.Save("")
</source>
<br>
Copying all attachments of a calculation to a sales invoice
<br>
<source lang="vb.Net">
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>
</source>

Latest revision as of 12:19, 5 January 2024

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