You need to sign in to do that
Don't have an account?
Burdah-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.
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
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.
If I will use standart apex/visualforce upload, can I return to my page, from which I have uploaded document ?
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.
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 >
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...
How to do file upload for any SObject using Visualforce.
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?
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"/>
Burdah-Moden,
what is the LastAttach.I am new in SFDC .I am trying to understand your code.