如何在 Windchill PDMLink 中以编程方式创建 WTDocument 并向其添加内容

使用 WTDocument.newWTDocument()创建一个文档,然后创建一个ApplicationData并将文件上传到它

注意: ContentServerHelper.service.updateContent () 是服务器端方法。它必须被远程调用。
    void createAndUpload(String name, String number, WTContainerRef product, Folder folder) throws WTInvalidParameterException, PropertyVetoException {
        Transaction tx = new Transaction();
        try {
            WTDocument doc = WTDocument.newWTDocument(name, number, DocumentType.getDocumentTypeDefault());
            doc.setContainerReference(product);
            doc.setDomainRef(((WTContainer) product.getObject()).getDefaultDomainReference());
            FolderHelper.assignLocation((FolderEntry) doc, (Folder) folder);
            // WTDoc needs to be stored before content may be added
            doc = (WTDocument) PersistenceHelper.manager.store(doc);
            ApplicationData theContent = ApplicationData.newApplicationData(doc);
            String filename = "test.txt";
            File theFile = new File("C:\\test.txt");
            theContent.setFileName(filename);
            // ContentRoleType.PRIMARY 上传文件为文档主内容; ContentRoleType.SECONDARY 上传文档为附件
            theContent.setRole(ContentRoleType.PRIMARY);
            theContent.setFileSize(theFile.length());
            FileInputStream fis = new FileInputStream(theFile);
            tx.start();
            theContent = ContentServerHelper.service.updateContent(doc, theContent, fis);
            ContentServerHelper.service.updateHolderFormat(doc);
            tx.commit();
            doc = (WTDocument) PersistenceHelper.manager.refresh(doc, true, true);
            fis.close();
        } catch (WTException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值