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

My requirement is whenever clicking on checkbox is true rendered choose file and save button it's working but my issue is after clicking on save button need to capture file name at below choose file here is the code ???
<apex:page controller="Fileattachment1"> <apex:form > <apex:pageBlock > <b><u><i>Attachment:</i></u></b><apex:inputCheckbox value="{!abool}"> <apex:actionSupport action="{!upload}" event="onchange"/> </apex:inputCheckbox> <br/><br/> <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file" rendered="{!abool}"/> <br/><br/> <apex:commandButton value="Save" action="{!Save}" rendered="{!abool}"/> </apex:pageBlock> </apex:form> </apex:page>
public with sharing class Fileattachment1 { public boolean abool{set;get;} public boolean bbool{set;get;} public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } public void check() { if(abool == true) { abool=true; } } public pagereference save() { attachment.OwnerId = UserInfo.getUserId(); attachment.ParentId = '0012800000JAVhi'; try { insert attachment; } catch (DMLException e) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment')); } finally { attachment = new Attachment(); } ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully')); return null; } public PageReference upload() { if(abool == true) { check(); } return null; } }
<apex:inputFile value="{!attachment.body}" id="file" rendered="{!abool}"/> \\remove (file://\\remove) filename
<apex:inputText value="f!attachment.name}" id="whateveryouwant" rendered="{!abool}"/>
This will rename the attachment filename on your visualforce page, no extra controller required.
For multiple attachments I use this code: You'll need to adjust it for the filename input using the logic above.
http://bobbuzzard.blogspot.com/2011/01/uploading-multiple-attachments-via.html