You need to sign in to do that
Don't have an account?
uploaded files to be saved in personal folder
HI,
Can anyone help me by answerwing, how to save the uploaded file in visualforce page to some "TEST" folder in documents. Please check teh code below:
VF page:
<apex:page standardController="Account" extensions="AttachmentUploadExtension">
<apex:form enctype="multipart/form-data">
<apex:pageMessages />
<apex:pageBlock >
<apex:pageBlockSection title="Attachment for Survey Monkey File" columns="2"/>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for="fileName"/>
<apex:inputFile value="{!document.body}" filename="{!document.name}" id="fileName"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!upload}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class AttachmentUploadExtension{
public AttachmentUploadExtension() {}
public ID folderid{get;set;}
public Attachment attachment {
get {
if (attachment == null)
attachment = new Attachment();
return attachment;
}
set;
}
public AttachmentUploadExtension(ApexPages.StandardController controller) {
}
public PageReference upload() {
attachment.OwnerId = UserInfo.getUserId();
attachment.IsPrivate = true;
try {
insert attachment;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
return null;
} finally {
attachment = new Attachment();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
return null;
}
}
Thanks,
taani
i am not seeing any document object usage in the code......i think you need to add the below lines
in your upload method you need to add the below points
get the respective folder id by using a query ....and you need to create a document object record to store in the respective folder..
folder obj = [select id from folder where name = 'x'];
document obj = new document();
obj.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents some thing like this ....
insert obj;