function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ganesh BollinaGanesh Bollina 

How do you fetch a document stored in article of some articletype and show it in a visualforce page

A document is uploaded to an article of some Article type, How to you fetch it in a Visualforce page and display ?
nitesh gadkarinitesh gadkari
Hi Ganesh,


You have to make use of Object Contentversion and use query example given below

[select id, Title, Description, FileType,
        Owner.Name, VersionNumber from ContentVersion
        Where IsLatest = true]

Exactly this cookbook article should get your job done.

http://developer.force.com/cookbook/recipe/displaying-salesforce-crm-content-documents-in-a-visualforce-page

Regards
Nitesh
nitesh gadkarinitesh gadkari
//###VFPAGE code###

<apex:page controller="ContentVersionAlt">
       <h1>Current User's Latest Version of All Accessible Files</h1>
    <apex:form >
     <apex:pageBlock >
       <apex:pageBlockTable var="cv" value="{!contentVersions}">
          <apex:column headerValue="URL" >
             <a href="/{!cv.id}">{!cv.title}</a>
          </apex:column> 
          <apex:column value="{!cv.description}" /> 
          <apex:column value="{!cv.FileType}" />
          <apex:column value="{!cv.Owner.Name}" />
          <apex:column value="{!cv.VersionNumber}" />
          </apex:pageBlockTable> 
     </apex:pageBlock>
     </apex:form>
       
</apex:page>

//### Controller ####

public class ContentVersionAlt {

    public List<ContentVersion> getContentVersions() {
        return [select id, Title, Description, FileType,
        Owner.Name, VersionNumber from ContentVersion
        Where IsLatest = true];
    }

}
this is working code.


Ganesh BollinaGanesh Bollina
Hi Nitesh, Thanks a lot, this solved my issue. But when we are adding this document in a custom field called attachement__c that query is throwing me an error. 
nitesh gadkarinitesh gadkari
Ganesh,

I think that is the wrong way to create a document through apex.In my Opinion either you use Blob or Document type instance to create document  and then store doc inthis object instance.Better you refer this cookbook link given below as to how include refer document in apex.

http://developer.force.com/cookbook/recipe/uploading-a-document-using-visualforce-and-a-custom-controller
 
Regards
Nitesh