Absent Member.
Absent Member.
562 views

Failed to Create Attachment

Hello,

I have tried to create an attachmenets but I got the following exception:

StackTrace = "   at TDAPIOLELib.IAttachment3.Post()\r\n   at ...

 

Code:

public static void uploadNewUrlAttachment1(Test test, string hyperlink)
        {
            try
            {
                if (!String.IsNullOrEmpty(hyperlink))
                {
                    FileInfo attachmentTemporaryFile = CreateUrlFile(hyperlink);

                    if (attachmentTemporaryFile != null)
                    {
                        AttachmentFactory attFactory = (AttachmentFactory)test.Attachments;

                        Attachment attachmentObject = (Attachment)attFactory.AddItem(System.DBNull.Value);
                        attachmentObject.Type = (int)tagTDAPI_ATTACH_TYPE.TDATT_FILE;
                        attachmentObject.FileName = attachmentTemporaryFile.FullName;
                        attachmentObject.Description = hyperlink;
                        attachmentObject.Post();
                        File.Delete(attachmentTemporaryFile.FullName);
                    }
                }
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }

 

this code works without any problem with Quality Center 10.0

 

Lanquage C#

I have Windows 7

ALM 11.52

 

could you help me?

Thanks

Tags (1)
0 Likes
1 Reply
Admiral
Admiral

Hi

 

Please verify that in VB works, it could be code logic issue or Com problem (Bug), please let me know your results.

 

Sample in vb

 

Sub Attachment_Load(Debug,  CurrentTestSet,  CurrentTest,  CurrentRun)
' Workflow script    On  Error  Resume  Next

    TDOutput.Clear

    Set  BugFact  =  TDConnection.BugFactory
    Set  theBug  =  BugFact.Item(21)
    Set  AttachFact  =  theBug.Attachments
    Set  theAttachmentsCollection  =  AttachFact.NewList("")
    Set  theAttachment  =  theAttachmentsCollection.Item(1)

    'This  works  in  VB,  but  not  in  VBScript:    'theAttachment.Load  True,  LoadPath    
    'In  VBScript,  use  this:    theAttachment.Load  True,  ""
    tdoutput.Print  theAttachment.FileName

    '  To  get  the  path  in  VBScript,  extract  it  from    '  the  filename:    theFileName  =  theAttachment.FileName
    tdoutput.Print  theFileName
    thePath  =  Left(theFileName,  InstrRev(theFileName,  "\")-1)
    tdoutput.Print  thePath

    '  handle  run-time  errors    If  Err.Number  <>  0  Then
        TDOutput.Print  "Run-time  error  ["  &  Err.Number  &  "]  :  "  &  Err.Description

        '  update  execution  status  in  "Test"  mode        If  Not  Debug  Then
            CurrentRun.Status  =  "Failed"
            CurrentTest.Status  =  "Failed"
        End  If
    End  If
End  Sub


"HP Support
If you find this or any post resolves your issue, please be sure to mark it as an accepted solution"
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.