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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

how to read data of secondary content file using API.

grainger-3
1-Newbie

how to read data of secondary content file using API.

Hello All,

I have a task in which i am to read data of attachment file(which is an xml file). can somebody guide me how i can achieve this. Is there any InputStream related API?

4 REPLIES 4
WhiteChen
5-Regular Member
(To:grainger-3)

1.PNG

Do you mean you want to get the marked file(your file name is xxxx.xml) via API?

Hello Chen,

Yes, basically i am using xml file for attachment, I am to read that xml tags in that file using APIs and generate UI based on those tags.

WhiteChen
5-Regular Member
(To:grainger-3)

I don't know how to read it online, but you can download it.

cadDoc is the host of the attachments.

EPMDocument latest = (EPMDocument) wt.vc.VersionControlHelper.service .allVersionsOf(cadDoc).nextElement();

ContentHolder holder = ContentHelper.service.getContents(latest);

Vector contents = ContentHelper.getContentListAll(holder);


Then you can traverse the contents then find the attachment and download it.

ContentServerHelper.service.writeContentStream((ApplicationData) contents.get(i), fullPath);


I'm not sitting in front of my IDE, but I think this should about do it.

ContentHolder holder = (ContentHolder)new ReferenceFactory().getReference(String oid).getObject();

holder = wt.content.ContentHelper.service.getContents(holder);

final QueryResult contents = ContentHelper.service.getContentsByRole(holder,ContentRoleType.SECONDARY);

whlie(contents.hasMoreElements()) {

  ContentItem ci = (ContentItem)contents.nextElement();

  if(ci instanceof ApplicationData) {

  ApplicationData ad = (ApplicationData)ci;

  try(final InputStream is = wt.content.ContentServerHelper.service.findContentStream(ad)) {

  //get file info from ad

  final File temp = File.createTempFile("xxx","xxx");

  FileUtils.copyInputStreamToFile(is, temp);

  }

  }

}

Top Tags