You need to sign in to do that
Don't have an account?

How to display image from document folder in VF page
Hi,
I have uploaded a image file using document and now i want to use that image in VF page. How to reference an image uploaded in document in VF Page?
Anyways,
I found the solution :) . I have modified my controllers code as follows and it woked like a charm!!!
public string getDocumentLogoUrl()
{
List<Document> lstDocument = [Select Id,Name,LastModifiedById from Document where Name = 'XXXXXXXXX' limit 1];
string strOrgId = UserInfo.getOrganizationId();
string strDocUrl = 'https://'+ApexPages.currentPage().getHeaders().get('Host')+ '/servlet/servlet.ImageServer?id='+lstDocument[0].Id+'&oid=' + strOrgId;
return strDocUrl;
}
All Answers
Hi,
After upload the image in document we can show the image on VF page by using below code snippet.
VF CODE:
<apex:image id="ph1" url="{!profile_photo_png}" styleclass="photo" width="113" height="113" alt="Your profile photo" />
Controller code:
public String profile_photo_png { get; set; }
string strOrgId = UserInfo.getOrganizationId();
string strDocUrl = '/servlet/servlet.ImageServer?oid=' + strOrgId + '&id=';
profile_photo_png = strDocUrl + doc.id // id of document
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi,
I am using the same sort of code. It is not working.
I am trying to generate "WordDoc" from VF Page. I have a logo and I want to show it on page. The logo is stored in "Documents" in under "My personal documents" and I made it externally available image.
the code is as follows:
VF Page -
<apex:image url="{!DocumentLogoUrl}" styleClass="photo"/>
Controller -
public string getDocumentImageUrl()
{
List<Document> lstDocument = [Select Id,Name from Document where Name = 'xxxxxxxxx' limit 1];
string strOrgId = UserInfo.getOrganizationId();
string strDocUrl = '/servlet/servlet.ImageServer?oid=' + strOrgId + '&id=';
system.debug('DocumentUrl*********' + strDocUrl + lstDocument[0].Id);
return strDocUrl + lstDocument[0].Id;
}
I am able to print the Url in debug statement. Also when i use the same url in browser.. its shows the Image, but not in "WordDoc". Any clue??
Thanks.
Anyways,
I found the solution :) . I have modified my controllers code as follows and it woked like a charm!!!
public string getDocumentLogoUrl()
{
List<Document> lstDocument = [Select Id,Name,LastModifiedById from Document where Name = 'XXXXXXXXX' limit 1];
string strOrgId = UserInfo.getOrganizationId();
string strDocUrl = 'https://'+ApexPages.currentPage().getHeaders().get('Host')+ '/servlet/servlet.ImageServer?id='+lstDocument[0].Id+'&oid=' + strOrgId;
return strDocUrl;
}
Hello, i was trying the Same thing and i found your code that looks similar to what i did, but unfortunately the image is not showing on Site/Portal, i don't know why, can any one give some help !!