Quantcast
Channel: PTC Community : Unanswered Discussions - Windchill
Viewing all articles
Browse latest Browse all 3592

Unable to find a attachment using ContentHelper

$
0
0

Hi All

 

     Inorder to download the attachment ContentServerHelper class is used, but the method is throwing null pointer exception.

 

Here the The ContentServerHelper.service.findContentStream(Applicationdata) throws null pointer exception.

 

Please find the below code snippet for reference

 

 

                    QuerySpec qs = new QuerySpec(wt.doc.WTDocument.class);

                    SearchCondition sc = new SearchCondition(wt.doc.WTDocument.class,"master>number","=","0000078558");

                    qs.appendWhere(sc);

 

 

 

 

                    QueryResult qr = PersistenceHelper.manager.find((wt.pds.StatementSpec)qs);

 

 

 

 

                              while(qr.hasMoreElements())

                              {

                                        WTDocument wtp = (WTDocument)qr.nextElement();

 

 

                                        ObjectReference or = ObjectReference.newObjectReference(wtp);

                                        ContentItem holder = ContentHelper.service.getPrimaryContent(or);

                                        if (holder!=null)

                                        {

 

                                                  ApplicationData applicationdata = (ApplicationData)holder;

 

 

                                                  try {

 

 

                                                            String fName=applicationdata.getFileName();

 

 

                                                            System.out.println(fName);

 

                                                            InputStream inputstream = ContentServerHelper.service.findContentStream(applicationdata);

 

 

                                                            int i = 0;

                                                            String filepath="D:\\exportfiles";

 

 

                                                            File temp=new File(filepath+File.separator+fName);

                                                            String docfile = temp.getAbsolutePath();

                                                            FileOutputStream tout = new FileOutputStream(docfile);

                                                            byte abyte0[] = new byte[2048];

                                                            while ( (i = inputstream.read(abyte0, 0, abyte0.length)) >= 0)

                                                            {

                                                            tout.write(abyte0, 0, i);

                                                            }

                                                            tout.close();

                                                  } catch (WTException e) {

                                                            // TODO Auto-generated catch block

                                                            e.printStackTrace();

                                                  }

 

 

 

 

 

 

                                        }


Viewing all articles
Browse latest Browse all 3592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>