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
AnnaTAnnaT 

inputFile does not work

Hi all,

 

I created the following Visualforce Page. This page is shown when [Edit] button is clicked.

If there is an attachment, <apex:inputFile> is hidden. But if "Remove Attachfile" link is clicked, <apex:inputFile> will be shown.

 

The problem is that, when <apex:inputFile> is changed from "hidden" to "shown" and new attachment is attached and [Save] button is clicked, no attachment is attached...

 

I think it is Visualforce problem, especially "rendered" problem, because when <apex:inputFile> is originally shown, it works properly.

I can't solve this problem... Please help me...

 

<apex:page standardController="Sample__c" extensions="Sample_Ext">  
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockButtons location="top">
        <apex:commandButton value="Save" action="{!save}" />
        <apex:commandButton value="Cancel" action="{!Cancel}"/>
      </apex:pageBlockButtons>
      <apex:actionRegion >
        <apex:pageBlockSection title="Attachment Section" columns="3" id="BS1" >
          <apex:pageBlockSectionItem rendered="{!isAttached1}" dataStyle="width:10%">
            <apex:commandLink value="{!attachment1.Name}" action="{!downloadAttachment}" target="_blank" >
              <apex:param name="attachId" value="{!attachment1.Id}" />
            </apex:commandLink>
            <apex:commandLink value="[Remove Attachfile]" action="{!Remove}" onclick="if(!confirm('Are you sure?')){return false;}" reRender="BS1">
              <apex:param name="removeId" value="remove1" />
            </apex:commandLink>
          </apex:pageblocksectionitem>
          <apex:pageBlockSectionItem rendered="{!isAttached1==False}" dataStyle="width:10%">
            <apex:inputFile value="{!file1Content}" fileName="{!file1Name}"/>
          </apex:pageblocksectionitem>
        </apex:pageBlockSection>
      </apex:actionRegion>     
    </apex:pageBlock>
  </apex:form>
</apex:page>

 Thanks in advance for your help.

 

Anna 

Ashish_SFDCAshish_SFDC
Hi Anna, 

See the code on the below links, 

http://blog.jeffdouglas.com/2010/04/28/uploading-an-attachment-using-visualforce-and-a-custom-controller/

http://corycowgill.blogspot.in/2011/01/i-see-lot-of-folks-posting-questions-in.html

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

Regards,
Ashish