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
AzusfdcAzusfdc 

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 ???

Capture Name below choose file when inserted
<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;
  }
}

 
Brian Cherry FWIBrian Cherry FWI
Are you wanting the user to set the file name?
AzusfdcAzusfdc
Exactly user to set the file name Brian Cherry here i need whatever the file have been attachment that name should replicate after clicking on save button Further is any feasibility is there at a time can we upload multiple files ???
Brian Cherry FWIBrian Cherry FWI
Aha, so you can simply to do this by 

    <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
 
AzusfdcAzusfdc
Brain you have mistaken little tricky after clicking on save button one file is inserted that file name should come under choose file and also keeping a delete button then that file should be deleted