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
Burdah-ModenBurdah-Moden 

Uploading document from visualforce page

Hello.

 

I have to know how I can upload document from visualforce page ?

Is there standart upload dialog  ?

 

Something like

<apexpage:uploaddocument name="upname">

 

 

 

Is it possible ?

Thank you.

Message Edited by Burdah-Moden on 03-14-2010 11:56 PM
Best Answer chosen by Admin (Salesforce Developers) 
Burdah-ModenBurdah-Moden

 

I have solved my problem.

I decide to publish code there, may be it helps other

 

 

 

global class MyClass { public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } public void save_attachment() { Account acc = [select id from Account limit 1]; attachment.parentid = acc.Id; insert attachment; LastAttach.add(attachment.Id); attachment = new Attachment(); } }

 

 Apex Page

 

 

<apex:page tabStyle="Opportunity" controller="MyClass" > <apex:form > <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/> <apex:commandButton value="Add attachment" id="EmailAttachAdd" action="{!save_attachment}" /> </apex:form > <apex:page >

 

 

 

 

 

All Answers

Burdah-ModenBurdah-Moden

Upd:

 

Found this link

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inputFile.htm

 

But I need to upload file with javascript, and show it dynamically on the visualpage.

 

I need to upload document without reloading page, is it possible to make it on javascript ?

 

If I will use standart apex/visualforce upload, can I return to my page, from which I have uploaded document ?

Message Edited by Burdah-Moden on 03-15-2010 01:30 AM
bob_buzzardbob_buzzard

I've used the standard VF upload to attach documents and then re-render a list of attached documents on the page.

 

You'll have to go back to the controller whichever way you do it, otherwise the document won't be sent.

 

I'd avoid trying to use Javascript as browsers are quite protective of the file uploading elements, to stop unscrupulous scripts stealing important files. 

Burdah-ModenBurdah-Moden

 

I have solved my problem.

I decide to publish code there, may be it helps other

 

 

 

global class MyClass { public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } public void save_attachment() { Account acc = [select id from Account limit 1]; attachment.parentid = acc.Id; insert attachment; LastAttach.add(attachment.Id); attachment = new Attachment(); } }

 

 Apex Page

 

 

<apex:page tabStyle="Opportunity" controller="MyClass" > <apex:form > <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/> <apex:commandButton value="Add attachment" id="EmailAttachAdd" action="{!save_attachment}" /> </apex:form > <apex:page >

 

 

 

 

 

This was selected as the best answer
dkndkn

Hi

 

I really appreciate your gesture for posting the code....thank you....but I was wondering where does document get attached after you attach this...

kkr.devkkr.dev

HI All,

 

   I am having an issue with required field validation on a page along with upload file.But if the validation of form fails then it removes the file path.It confuses end users.How to fix this?

@login.ax974@login.ax974

Hi Everyone,

 

Can someone please help me get some example for multiple file upload using VF?

 

I need to add the row dynamically. My current code just have one row and i want to plug the code into it - it is something like as given below - but when i try doing a rerender from a command button it says "apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute. ".

 

Can someone please help and suggest any alternative? Really appreciate all help here.

 

<apex:pageBlock title="{!pageTitle}" id="pb">
<apex:pageBlockTable value="{!listDoc}" var="Doc" id="pgbt">
<apex:column headerValue="Document Name" >
<apex:inputField value="{!Doc.Document_Name__c}" required="true" id="docName"/>
</apex:column>
<apex:column headerValue="Document Type">
<apex:inputField value="{!Doc.Type__c}" required="true"/>
</apex:column>
<apex:column >
<apex:inputFile value="{!docContent}" contentType="{!docContentType}" fileName="{!fileName}"/>
</apex:column>
</apex:pageBlockTable>

<apex:commandButton action="{!addMoreRows}" value="Add Rows" id="AddRows" reRender="pgbt"/>
<apex:commandButton action="{!UploadDoc}" value="Upload" id="UploadDoc"/>

 

Mayur ChwdharyMayur Chwdhary
Hi 
Burdah-Moden,

what is the LastAttach.I am new in SFDC .I am trying to understand your code.