Skip to main content
1-Visitor
August 6, 2014
Solved

How to set Primary content and secondary content of a Document using API?

  • August 6, 2014
  • 2 replies
  • 5607 views

How to set Primary content and secondary content of a WTDocument using API?

Best answer by JarrettOberg

Hi Vineeth,

There is a very nice article for this exact issues:https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS18364

  • Create a document:

WTDocument doc = WTDocument.newWTDocument(name, number, DocumentType.getDocumentTypeDefault());

  • Create ApplicationData and upload a file to it.

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

2 replies

1-Visitor
August 11, 2014

primary

ContentHolderHelper.setContents(wtDocument, dataArray[], ContentRoleType.PRIMARY, name, "", false);

1-Visitor
August 15, 2014

Hi Vineeth,

There is a very nice article for this exact issues:https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS18364

  • Create a document:

WTDocument doc = WTDocument.newWTDocument(name, number, DocumentType.getDocumentTypeDefault());

  • Create ApplicationData and upload a file to it.

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