Issue while adding attachment to QC Test Case using Com4j API

I am trying to add attachment to QC Test LAB Test Case run from my Java code using Com4J API. I was able to create a successful run, however while adding attachments below code is throwing invalid parameter for "IAttachment attach = attachfac.addItem(null).queryInterface(IAttachment.class);". In this case additem is expecting Java Item Object. I also tried to pass addItem(""), but then attach.Type(1) is failing with reason:- Attachment Type cannot be changed. Could anyone please help me with this:

 IBaseFactory obj2 = testset.tsTestFactory().queryInterface(IBaseFactory.class);
 IList tstestlist = obj2.newList("");
  for(Com4jObject obj3:tstestlist){
   ITSTest tstest = obj3.queryInterface(ITSTest.class);
    if(tstest.name().contentEquals("[1]TC1")){
    System.out.println("TC found");
    IRunFactory runfactory = tstest.runFactory().queryInterface(IRunFactory.class);
    IRun run=runfactory.addItem("RunNew").queryInterface(IRun.class);
    run.status("Passed");
    IAttachmentFactory attachfac = run.attachments().queryInterface(IAttachmentFactory.class);
    IAttachment attach = attachfac.addItem("").queryInterface(IAttachment.class);
    attach.type(1);
    attach.fileName("Path to File TC1");
    attach.post();
    run.post();.

Answers


String fileName = new File(Attachment).getName();
String folderName = new File(Attachment).getParent();

try{
        IAttachmentFactory attachfac = tsteststeps.attachments().queryInterface(IAttachmentFactory.class);
    IAttachment attach = attachfac.addItem(fileName).queryInterface(IAttachment.class);
        IExtendedStorage extAttach = attach.attachmentStorage().queryInterface(IExtendedStorage.class);
    extAttach.clientPath(folderName);  
    extAttach.save(fileName, true);
    attach.description(Actual);
    attach.post();
    attach.refresh();                               
}catch(Exception e) {
    System.out.println("QC Exceptione : "+e.getMessage());
}

Need Your Help

The INSERT statement conflicted with the constraint

sql datetime timestamp constraints check-constraints

I want to make a date constraint in my table (I use sql server). I want to make sure that the date in one of my columns is later than the current date and time (I know it sounds weird, but it's an