You need to sign in to do that
Don't have an account?

File Upload Query
Hi,
Can anyone tell me how to get the extension of the file being uploaded in the documents tab ?
You need to sign in to do that
Don't have an account?
Hi,
Can anyone tell me how to get the extension of the file being uploaded in the documents tab ?
Hi you can try this,
<apex:page controller="FileUploadController" showHeader="false">
<apex:sectionHeader subtitle="Attach Documents"/>
<apex:form enctype="multipart/form-data">
<apex:pageMessages />
<apex:pageBlock title="Upload a File">
<apex:pageBlockButtons location="Bottom">
<apex:commandButton action="{!upload}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="1" 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>
</apex:pageBlock>
</apex:form>
</apex:page>
public with sharing class FileUploadController {
public Document document {
get {
if (document == null)
document = new Document();
return document;
}
set;
}
public PageReference upload() {
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId(); // put it in running user's folder
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;
}
}
There's no restriction to the files getting uploaded. I want to restrict certain files like .dll, .bat etc. from getting uploaded.
Hi ,
I've already iimplemented a similar code .. I m afraid but it does not satisfy our purpose ..
I want to get the extension of the file being uploaded in order to restrict some file types from being uploaded ( exe , dll etc )