+ Start a Discussion
Alexander KrykunAlexander Krykun 

How to download some file from visual force page

I have the following task 

I have several links on page from which some files must be downloaded
 Presently I don't know  what exactly format it will be. So let's assume it can be anything(.img, .exe, .txt. etc)

So I need to know approaches how to provide downloading all the formats
Can someone please provide me with such  API references or documentation to accomplish that aim

NagendraNagendra (Salesforce Developers) 
Hi Alexander Krykun,

Please try the below sample code1:
<apex:page contentType="application/x-excel#RenderAsTestFile.xls" standardController="TestObject__c">
    <apex:pageBlock >
        <apex:pageblockTable value="{!TestObject__c}" var="v" border="1"
                                     columnsWidth="100px,200px,150px" cellspacing="0" cellpadding="8">
            <apex:column headerValue="Id">{!v.Name}</apex:column>
            <apex:column headerValue="Name">{!v.Name__c}</apex:column>
            <apex:column headerValue="Contact Number">{!v.Mobile__c}</apex:column>
            <apex:column headerValue="Mail id">{!v.Mail_id__c}</apex:column>
        </apex:pageblockTable>
    </apex:pageBlock>   
</apex:page>
Please try the below sample code2:
<apex:page contentType="image/jpg#samplelogo.jpg" >
<apex:form >
<apex:pageBlock >
<apex:image url="http://science-all.com/images/wallpapers/car-hd-wallpaper/car-hd-wallpaper-17.jpg"/>
</apex:pageBlock>
</apex:form>
</apex:page>



Please mark it as solved if it helps you.

Best Regards,
Nagendra.P