i am creating a VF page on which i want to show all the files uploaded in chatter with its name,created by,created date and file icon . All the things are done except the icon. can anyone tell me how can i show the icon in front of files.(if a file is pdf file, pdf icon should appear and same for all other file types)

<apex:repeat  value="{!lstattachments}"  var="a">
  <apex:image url="{!URLFOR($Resource.TestZip, 'images/pdficon.jpg')}" width="50"   height="50" rendered="{!CONTAINS(a.ContentType,"pdf")}"/>
  <apex:image url="{!URLFOR($Resource.TestZip, 'images/excelicon.jpg')}" width="50"  height="50" rendered="{!CONTAINS(a.ContentType,"excel")}"/>

One way to achive this is store icons in static resource and based on content type use this and render the images.

Note you can also use dynamic visualforce components to achieve this .Logic will be based on content type you can generate apex image tag from the backend .

Note how i have used contains in the formula to detect whether the file is PDF or excel.


If the solution is for the content document then from the ContentDocument Object there is a field called parentId .From the ParentId field one has to traverse up to the Contant version and take its file type or Content URL to detect the type of file

| improve this answer | |
  • hey i am getting all the files from contentDocument by the query [select title,createdDate,createdBy.firstname from contentdocument]. so i think contentDocument dont have any method contentType. I need all the files that were attached with feeds,comments etc in chatter. If you have any other method also, please tell me. – Sachin Kadian Aug 25 '13 at 9:41
  • You will have to grab the parent Id and then look for file type to determine file type .I have updated my answer.Thanks – Mohith Shrivastava Aug 25 '13 at 11:58
  • I guess you need to use "LatestPublishedVersionId" field on Content to go to "ContentVersion" object and then use "FieldType" to get the type of a file – ForceDeveloper Aug 26 '13 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.