You need to sign in to do that
Don't have an account?
Alex Kirby
Uploading document using visualforce file extension?
Hi all,
I have a controller and a vf page to upload documents to a folder in our community. The file uploads successfully but the file extension is not captured in the process causing issues when trying to open the file.
VF:
Controller:
Result:
The top file I entered using standard salesforce in the backend as a test.
Any help is appreciated, cheers.
I have a controller and a vf page to upload documents to a folder in our community. The file uploads successfully but the file extension is not captured in the process causing issues when trying to open the file.
VF:
<apex:pageBlock > <apex:pageBlockSection showHeader="false" columns="2" id="block1"> <apex:pageBlockSectionItem > <apex:outputLabel value="File Name" for="fileName"/> <apex:inputText value="{!document.name}" id="fileName"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="File" for="file"/> <apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Description" for="description"/> <apex:inputTextarea value="{!document.description}" id="description"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Keywords" for="keywords"/> <apex:inputText value="{!document.keywords}" id="keywords"/> </apex:pageBlockSectionItem> </apex:pageBlockSection>
Controller:
public with sharing class qmtDocuments { List<Folder> fld = [Select id from Folder where DeveloperName ='qmtDocumentsFolder' limit 1]; public List<Document> getDocuments() { return [select id, Name, Description, ContentType from Document Where FolderId =:fld]; } public Document document { get { if (document == null) document = new Document(); return document; } set; } public PageReference upload() { document.AuthorId = UserInfo.getUserId(); document.FolderId = string.valueof(fld[0].get('id')); // put it in running user's folder document.name = document.name; try { insert document; } catch (DMLException e) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file')); return null; } finally { document.body = null; // clears the viewstate document = new Document(); } ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully')); return null; } }
Result:
The top file I entered using standard salesforce in the backend as a test.
Any help is appreciated, cheers.
from the above, this uploads the filename with the extensions attached using <apex:inputfile>. I can't expose this functionality to the community though as I am unable to give create permissions to community users for documents
All Answers
Try the updated visualforce code below
from the above, this uploads the filename with the extensions attached using <apex:inputfile>. I can't expose this functionality to the community though as I am unable to give create permissions to community users for documents