+ Start a Discussion
udayar_jayamudayar_jayam 

How to add new line in plain text

Hi All,

      I trying to download program for contact object , the user click the "Download" custom button it should download all the records from the  object. This download file should in text format(.txt).when i download a file it display like this

johnkumarjane but i want to display like this in text file

john

kumar

jane

how to add break line in controller please anyone advice me.

public class contactquery{

    public List<Contact> cs{get; set;}
    public string empId;
    public contactquery() 
    {
    cs = new List<Contact>();
       for (Contact c : [Select id, Name from Contact ])
       {           
           cs.add(c);          
           
       }
       
    }
}



Vf Page:
<apex:page Controller="contactquery" contentType="text/plain/#emp.txt"  cache="true">
<apex:repeat value="{!cs}" var="contact">
<apex:outputText value="{!contact.Name}" escape="false"/><br/>
</apex:repeat>
 </apex:page>

 

 

bob_buzzardbob_buzzard

Its the outputtext that causes everything to stick on one line - if you just use plain merge fields it works okay - for example, this code:

 

<apex:page standardcontroller="Account" recordsetvar="accounts" cache="true" 
contentType="text/plain/#test.txt"> 
Name;City
<apex:repeat value="{!accounts}" var="acc">
{!acc.name};{!acc.BillingCity}
</apex:repeat>
</apex:page>

 produces the following output from my dev org:

 

 
Name;City
Acme;
Blog Acc 4;
Blog Acc 4;
Blog Acc 5;
Blog Acc 7;
Blog Acc 8;
Blog Acc1;
Blog Acc2;
Blog Acc3;
Blog Account;
Blog Account;
Blog Account;
Boards Test;
Boards Test;
Boards Test;
Boards Test;
Boards Test;
Boards Test;
BrightGen;Witham
Bulk Acc 0;

Obviously you lose the capability to format that outputtext gives you, so this might not be suitable for your use case.

 

 

udayar_jayamudayar_jayam

Hi Bob

     Thanks for reply im already tried this format but its not working well now also i tried your same code it showing like this

 


Name;CityBurlington Textiles Corp of America;BurlingtonDickenson plc;LawrenceEdge Communications;

bob_buzzardbob_buzzard

What tool are you using to open the file in?  I open it in any text editor and it looks fine.

udayar_jayamudayar_jayam

Notepad 

bob_buzzardbob_buzzard

I don't know what to tell you - it looks fine in every text editor I've tried.