SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 9 of 9
  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Error with Attachment.FileName in OTA API ...

    Hello,

    I am trying to upload an attachment to a Test Instance in a Test Set. All is well with one exception (using QC Version 9.4353) - when I try to set the Attachment.FileName to the path\filename of a local file I get an error "File name can not be changed" ...

    Here is a snippet of my code:

    Dim AttFact As TDAPIOLELib.AttachmentFactory
    Dim Att As TDAPIOLELib.Attachment
    AttFact = TestInstance.Attachments
    Att = AttFact.AddItem("")
    Att.Type = 1 'TDATT_FILE
    Att.FileName = HTMLSummaryFilename
    Att.Post()

    When I look into the OTA API reference it says that the FileName property for an Attachment object is Read-Only - which would make sense with this error but in all the examples (even in the same section of the OTA API reference) this is how it is done.

    Help?

    Thanks,

    Jay

  2. #2
    Junior Member
    Join Date
    Jan 2008
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    One slight change - the OTA API reference does say that the FileName method is Read-Write - though this doesn't change the problem.

  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    So it looks like this is happening because the filename that I am passing includes the path - so if I just give QC a filename how does it know where to get the file?

  4. #4
    Junior Member
    Join Date
    Jan 2008
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    Here is the filename:

    "qcreporttesting 2007.1229.16.15.54.616 E.fftr"

  5. #5
    Senior Member
    Join Date
    Oct 2001
    Location
    Nashville, TN, USA
    Posts
    713
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    Try the following (I haven't tested this, but this is the VBScript equivalent of what I do in C#):

    <font class="small">Code:</font><hr /><pre>
    Dim AttFact As TDAPIOLELib.AttachmentFactory
    Dim Att As TDAPIOLELib.Attachment
    AttFact = TestInstance.Attachments
    Dim Args As Variant(0 to 1)
    Args(0) = HTMLSummaryFilename ' Full path to the file here
    Args(1) = 1 ' tagTDAPI_ATTACH.TDATT_COPY indicates copy to server
    Set Att = AttFact.AddItem(Args)
    Att.Post()
    </pre><hr />

    The key here is setting up the array and passing that to the AddItem method. You may have to play with the type of the array if it doesn't like Variant.

    I also found the following in the v9.2 OTA guide that uses Extended Storage to upload an attachment. Interesting approach (titled "Creating a new defect attachment" if you want to search for it).

    <font class="small">Code:</font><hr /><pre>
    Public Sub UploadDefectAttachment()
    ' This routine adds file "D:\temp\A\SampleAttachment.txt"
    ' as an attachment to a defect. The file must exist
    ' at that path before running the routine

    Dim BugFact As BugFactory
    Dim bugObj As Bug
    Dim attachFact As AttachmentFactory
    Dim attachObj As Attachment
    Dim ExStrg As IExtendedStorage
    Dim rc

    'Get the bug factory from the TDConnection
    'tdc is the global TDConnection object.
    Set BugFact = tdc.BugFactory
    'Get a bug object
    'To see how to get this specific bug without knowing the D,
    ' See example
    '"Downloading a defect attachment with Extended Storage"
    ' for ExtendedStorage.Load
    Set bugObj = BugFact.Item(2)
    '-----------------------------------------
    'Use Bug.Attachments to
    'get the bug attachment factory
    Set attachFact = bugObj.Attachments
    'Add a new extended storage object,an attachment
    ' named SampleAttachment.txt
    Set attachObj = attachFact.AddItem"SampleAttachment.txt")
    'Modify the attachment description
    attachObj.Description = "Bug Sample Attachment"
    'Update the attachment record in the project database
    attachObj.Post
    'Get the bug attachmeent extended storage object
    Set ExStrg = attachObj.AttachmentStorage
    'Specify the location of the file to upload.
    ExStrg.ClientPath = "D:\temp\A"
    '-----------------------------------------
    'Use IExtendedStorage.Save to
    'upload the file
    ExStrg.Save "SampleAttachment.txt", True
    ExStrg.GetLastError
    Debug.Print err.Description
    End Sub
    </pre><hr />

    Hope this helps, and sorry for any code errors since this isn't tested.
    Boyd Patterson
    Patterson Consulting, LLC
    www.patterson-consulting.net

    [i]Creator of Test Design Studio - Powerful IDE for QuickTest Pro[i]

  6. #6
    Junior Member
    Join Date
    Jan 2008
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    Your first part got it! THANKS!

    The second part is interesting as well. Here is my VB 2008 code:

    Dim AttFact As TDAPIOLELib.AttachmentFactory
    Dim Att As TDAPIOLELib.Attachment
    AttFact = TestInstance.Attachments
    Dim Args(0 To 1)
    Args(0) = HTMLSummaryFilename
    Args(1) = 1
    Att = AttFact.AddItem(Args)
    Att.Post()

    Thanks again!

    -Jay

  7. #7
    Senior Member
    Join Date
    Oct 2001
    Location
    Nashville, TN, USA
    Posts
    713
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    Excellent! Glad that did the trick for you!
    Boyd Patterson
    Patterson Consulting, LLC
    www.patterson-consulting.net

    [i]Creator of Test Design Studio - Powerful IDE for QuickTest Pro[i]

  8. #8
    Junior Member
    Join Date
    Dec 2007
    Posts
    28
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    In add I post a code in VBS that attached all files existing in a folder :
    <font class="small">Code:</font><hr /><pre>Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\.\root\cimv2")
    Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Path = '\\temp\\'")
    Set AttacheFile = CurrentRun.Attachments
    For Each objFile in colFiles
    Set AttacheItem = AttacheFile.AddItem(Null)
    'msgbox objFile.Name
    AttacheItem.FileName = objFile.Name
    AttacheItem.Type=1
    AttacheItem.Post 'Mise jour de la modification sur le serveur de TestDirector.
    Next
    Set AttacheFile = nothing
    Set AttacheItem = nothing</pre><hr />

    Version 9.2 of QC

  9. #9
    Junior Member
    Join Date
    Dec 2008
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Error with Attachment.FileName in OTA API ...

    Thank you for you vbs..

    I spent 2 hours on this without answer, now I know that.

    This is my script:

    Dim att As TDAPIOLELib.Attachment
    Dim atts As TDAPIOLELib.AttachmentFactory

    atts = r.Attachments

    ' att = atts.AddItem(DBNull.Value)
    ' att.Load(True, "C:\Documents and Settings\Administrator\&amp;#26700;&amp;#38754;\1. txt")
    'att.f()
    '' att.Load(True, "C:\Documents and Settings\Administrator\&amp;#26700;&amp;#38754;\1. txt")
    ' att.Save(True)
    Dim Args(0 To 1)

    Args(0) = "D:\1.TXT" ' HTMLSummaryFilename ' Full path to the file here
    Args(1) = 1 ' tag TDAPI_ATTACH.TDATT_COPY indicates copy to server

    'att = atts.AddItem(DBNull.Value)
    att = atts.AddItem(Args)


    ' att.AttachmentStorage(
    'att.AutoPost = True
    ' att.Refresh()
    '

    att.Post()
    'att.Save(True)
    ' att.Refresh()
    ' r.Post()

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.00%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 12:14 AM.

Copyright BetaSoft Inc.