PdcAttachment.Save: Difference between revisions

From External Bemet Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:


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


== Notes ==
== Notes ==
If the FilePath is an empty string, then it is assumed that the file is located in the Bemet temp directory. In this case the Attachment.FileName is used to locate the file in the temp directory
This function will work onPrem, or in the cloud with either the Document Repository or Sharepoint.<br>
and to load this file in a steam, before it is saved in the Document Repository, Sharepoint, or the attachment table.<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 FilePath is not empty, it will assume that it contains a full path to the file that you want to save. In this case the path should contain both the filepath and the filename. <br>
# 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>
<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)  
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)  
Line 15: Line 17:


== Code example ==
== Code example ==
This example adds a new text file from a specific path 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.Save("C:\test.txt")
Dim newAttach As PDCEXT.IPdcAttachment = calcAttachList.Add()
end if
newAttach.FileName = "NewFile.pdf"
newAttach.TempFilePath = "C:\AFolder\NewFile.pdf"
newAttach.Save("")
</source>
</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)


This example adds a new text file from the Bemet temp directory to calculationnumber 12345
    Dim copyAttachment As PDCEXT.IPdcAttachment = invAttachList.Add
<source lang="vb.Net">
    copyAttachment.FileName = attachment.FileName
Dim attachmentlist As PDCEXT.PdcAttachmentList = PDC.App.AttachmentList
    copyAttachment.TempFilePath = attachment.TempFilePath
if attachmentlist.Read("DO_CALC", "", "12345") then
    copyAttachment.Save("")
  dim attachment = attachmentlist.add
Next
  attachment.filename = "test.txt"
</source>
  attachment.Save("")
end if
</source>
</source>

Revision as of 12:18, 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

</source>