Quantcast
Channel: PTC Community: Message List - Windchill
Viewing all articles
Browse latest Browse all 8876

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

$
0
0

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


Viewing all articles
Browse latest Browse all 8876

Trending Articles