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
Minky VaidMinky Vaid 

How to add attachment section in Visual force page

I have created a custom button which calls Visual force page on the visual force page I want to display 

attach file link so users can attach files just like tasks or any other object

User-added image
Chandra Sekhar CH N VChandra Sekhar CH N V
Not sure if this is what you are looking for , I am posting mine which uploads a file and adds up to the attachment list. You can tweak this as per your requirements.
 
public class uploadAttachmentsController {
    public uploadAttachmentsController(ApexPages.StandardController controller){}
    public Attachment file;
        public Attachment getfile(){
            file = new Attachment();
            return file;
        }
        public PageReference save(){
            string recordid = System.currentPageReference().getParameters().get('id');
            Attachment attach = new Attachment(
                parentid = recordid,
            	name = file.name,
            	body = file.body);
            insert attach;
            return null;
        }
}


====================================================

<apex:page standardController="Account" extensions="uploadAttachmentsController">
    <apex:form>
    <apex:pageBlock>
        <apex:inputFile value="{!file.body}" fileName="{!file.name}"></apex:inputFile>
        <apex:commandButton value = "save" action="{!save}"/>
        </apex:pageBlock>
    
    </apex:form>
</apex:page>

Let me know if it was helpful.
Ajay K DubediAjay K Dubedi
Hi,
I think it should work pretty much the same way if it's an image or a Word document. 
You might want to try these links. They might actually be more helpful than uploading my code since they are more simpler since I have several other things in mine that might make it a bit more confusing such as limit the upload size of an image as well as allow users to only upload 7 pictures.  
http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-controller/
http://salesforcetrekbin.blogspot.com/2010/04/visualforce-file-upload-for-any-sobject.html
 Let me know if this helps or you need any other ideas! 
I should also mention, maybe you already knew or figured, but each attachment must be associated with a record in the URL like www.mydomain.com/page?id={object__c.id}

Thanks.