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

How to read a imported file in the Visualforce page
This file is sample tab Elimated Text file .. how to read this file and add to the List and render in visualforce page in Salesforce ..!
Apex Class:
visualforce page:
how to add to list and display in the visualforce page ....!
Please share any related links it might be help full thank you...!
public class Textfileimport{ public blob Selectedfile{get;set;} public list<Studentdetails> Lststudentdetails{get;set;} public Textfileimport(){ Lststudentdetails= new list<Studentdetails>(); } public void add(){ } //wrapperclass public class Studentdetails{ public string studentname{get;set;} public string studentId{get;set;} public integer studentyear{get;set;} } }
visualforce page:
<apex:page Controller="Textfileimport" > <apex:messages /> <apex:form id="theForm"> <apex:inputFile value="{!Selectedfile}" id="testhide" /> <apex:commandButton value="ImportValues" action="{!add}"/> <apex:pageBlock > <apex:pageblockTable value="{!Lststudentdetails}" var="a" > <apex:column headerValue="Name">{!a.studentname} </apex:column> <apex:column headerValue="Id" >{!a.studentId}</apex:column> <apex:column headerValue="Year">{!a.studentyear}</apex:column> </apex:pageblockTable> </apex:pageBlock> </apex:form> </apex:page>
how to add to list and display in the visualforce page ....!
Please share any related links it might be help full thank you...!
public class Textfileimport{
public blob Selectedfile{get;set;}
public list<Studentdetails> Lststudentdetails{get;set;}
public Textfileimport(){
Lststudentdetails= new list<Studentdetails>();
}
public void add(){
string fileContent = Selectedfile.toString();
List<string> Rows = fileContent.split('\n');
for(String Row: Rows)
{
List<string> rowcolumns = Row.split('\t');
Studentdetails sd = new Studentdetails();
sd.studentname = rowcolumns[0];
sd.studentId = rowcolumns[1];
sd.studentyear = rowcolumns[2];
Lststudentdetails.add(sd);
}
}
//wrapperclass
public class Studentdetails{
public string studentname{get;set;}
public string studentId{get;set;}
public integer studentyear{get;set;}
}
}