cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

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

ptc-6328570
1-Newbie

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

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

2 REPLIES 2

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

  • 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

Top Tags