Skip to Content
author's profile photo Former Member
Former Member

Removing attachments from Purchase Order using DIAPI

Dear all,


I have added attachment to PO using DIAPI. I have given below the code.


Dim oAtt As SAPbobsCOM.Attachments2 = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oAttachments2)
Dim FileName As String = ""
Dim SourceFile As String = ""
Dim DestinationFile As String = ""


For i As Integer = 0 To PurchaseOrderInfo.Attachments.Length - 1


FileName = PurchaseOrderInfo.Attachments(i).FileName
SourceFile = PurchaseOrderInfo.Attachments(i).SourcePath & "\" & FileName
DestinationFile = PurchaseOrderInfo.Attachments(i).TargetPath & "\" & FileName


If i > 0 Then oAtt.Lines.Add()
oAtt.Lines.SetCurrentLine(i)
oAtt.Lines.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName)
oAtt.Lines.FileExtension = Replace(System.IO.Path.GetExtension(FileName), ".", "")
oAtt.Lines.SourcePath = PurchaseOrderInfo.Attachments(i).SourcePath

If System.IO.File.Exists(DestinationFile) Then
System.IO.File.Delete(DestinationFile)
End If


If PurchaseOrderInfo.Attachments(i).Override = True Then
oAtt.Lines.Override = SAPbobsCOM.BoYesNoEnum.tYES
Else
oAtt.Lines.Override = SAPbobsCOM.BoYesNoEnum.tNO
End If


Next


Dim iAttEntry As Integer = -1
Dim lResult As Long
Dim lErrCode As Long, sErrMsg As String = ""


lResult = oAtt.Add()


It works fine. But, I am not able to remove an attachment via diapi.


Could you please help me how to solve this.


Thanks in advance.


Manikandan

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2014 at 02:53 AM

    Hi Manikandan,

    I guess that I would recreate a new Attachment2 object, by copying the lines that I want to keep and specifying the Override = tYES and doing a File.Delete on the file I want to remove.

    At the end, attach the new Attachment2 object to the PO (which isn't done in your code.

    I agree, it could be eathier...

    Regards,

    Eric

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.