=============VFPages==================
<apex:page controller="fileupload">
<apex:sectionHeader title="fileupload"/>
<apex:form enctype="format-data">
<apex:pageBlock title="upload a file">
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!upload}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="true" columns="2" id="Block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="file name" for="filename">
<apex:inputText value="{!Documentname}" id="filename"/>
</apex:outputLabel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="file discription" for="file discription">
<apex:inputFile value="{!DoBody}" fileName="{!Documentname}" id="file">
</apex:inputFile>
</apex:outputLabel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="description" />
<apex:inputTextarea value="{!dodescription}" id="description" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Keywords" for="Keywords">
<apex:inputText value="{!DoKeywords}" id="Keywords"/>
</apex:outputLabel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
===========Controller=======================
public with sharing class fileupload {
public String DoKeywords { get; set; }
public String dodescription { get; set; }
public String DoBody { get; set; }
public String Documentname { get; set; }
// public String Document { set; }
public Document document{
get{
if(document == null)
document= new Document();
return document;
}
set;
}
public PageReference upload() {
// document.AuthorId = UserInfo.getUserId();
//document.FolderId = UserInfo.getUserId();
try{
insert Document;
}
catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
}
finally {
DoBody=null;
Documentname=null;
Document=new Document();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
return null;
}
}
<apex:page controller="fileupload">
<apex:sectionHeader title="fileupload"/>
<apex:form enctype="format-data">
<apex:pageBlock title="upload a file">
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!upload}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="true" columns="2" id="Block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="file name" for="filename">
<apex:inputText value="{!Documentname}" id="filename"/>
</apex:outputLabel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="file discription" for="file discription">
<apex:inputFile value="{!DoBody}" fileName="{!Documentname}" id="file">
</apex:inputFile>
</apex:outputLabel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="description" />
<apex:inputTextarea value="{!dodescription}" id="description" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Keywords" for="Keywords">
<apex:inputText value="{!DoKeywords}" id="Keywords"/>
</apex:outputLabel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
===========Controller=======================
public with sharing class fileupload {
public String DoKeywords { get; set; }
public String dodescription { get; set; }
public String DoBody { get; set; }
public String Documentname { get; set; }
// public String Document { set; }
public Document document{
get{
if(document == null)
document= new Document();
return document;
}
set;
}
public PageReference upload() {
// document.AuthorId = UserInfo.getUserId();
//document.FolderId = UserInfo.getUserId();
try{
insert Document;
}
catch(DMLException e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
}
finally {
DoBody=null;
Documentname=null;
Document=new Document();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
return null;
}
}
No comments:
Post a Comment