Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
How to set Primary content and secondary content of a WTDocument using API?
Solved! Go to Solution.
Hi Vineeth,
There is a very nice article for this exact issues:https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS18364
WTDocument doc = WTDocument.newWTDocument(name, number, DocumentType.getDocumentTypeDefault());
ApplicationData theContent = ApplicationData.newApplicationData(doc);
String filename = "test.txt";
File theFile=new File("C:\\test.txt");
theContent.setFileName(filename);
theContent.setUploadedFromPath(path);
theContent.setRole(ContentRoleType.toContentRoleType("PRIMARY")); //if it’s secondary, use “SECONDARY”
theContent.setFileSize(theFile.length());
FileInputStream fis = new FileInputStream (theFile);
theContent = ContentServerHelper.service.updateContent(doc, theContent, fis);
ContentServerHelper.service.updateHolderFormat(doc);
doc = (WTDocument) PersistenceHelper.manager.refresh((Persistable)doc, true, true);
fis.close();
Hopefully this helps you with your implementation.
Thanks,
Jarrett
primary
ContentHolderHelper.setContents(wtDocument, dataArray[], ContentRoleType.PRIMARY, name, "", false);
Hi Vineeth,
There is a very nice article for this exact issues:https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS18364
WTDocument doc = WTDocument.newWTDocument(name, number, DocumentType.getDocumentTypeDefault());
ApplicationData theContent = ApplicationData.newApplicationData(doc);
String filename = "test.txt";
File theFile=new File("C:\\test.txt");
theContent.setFileName(filename);
theContent.setUploadedFromPath(path);
theContent.setRole(ContentRoleType.toContentRoleType("PRIMARY")); //if it’s secondary, use “SECONDARY”
theContent.setFileSize(theFile.length());
FileInputStream fis = new FileInputStream (theFile);
theContent = ContentServerHelper.service.updateContent(doc, theContent, fis);
ContentServerHelper.service.updateHolderFormat(doc);
doc = (WTDocument) PersistenceHelper.manager.refresh((Persistable)doc, true, true);
fis.close();
Hopefully this helps you with your implementation.
Thanks,
Jarrett