function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RICARDO PALMARICARDO PALMA 

How to change the location where files are saved(Download) in a VF page.

Hi all,

I have a VF page that creates a json file after a button have been clicked. The problem is that the file is always downloaded on  C:\User\Download 
I can change the location on the browser, but I don't want to do that because I will have all kind of files downloaded by the users.
This action will be executed by multiple users.

I'm open to any suggestions, but here is what I need to do.
1. I want to be able to save the on a ftp server. This is my first option. I did some research and it looks like is not way to connect to FTP server using Apex.
or 
2. I want to able to save the file on a different map network drive.

I tried creating a  .bat file to move all the .json files from C:\User\Download  to my ftp server setting a task. The problem is that if the user turn off the pc before the task is executed the file never going to be moved to the FTP server or the map drive. I need something more REAL TIME.
1. Click the button
2. Save the file on the ftp or the map drive. 

Here is my VF page
 
<apex:page Controller="IDR" sidebar="false" action="{!fetch}" contentType="text/plain/#{!media.City_Code__c}_{!IssueDate}.json" cache="false">
{"mediaCode":"{!media.City_Code__c}","mediaName":"{!media.Name}","issueDate":"
<apex:outputText value="{!IssueDate}"/>
","secondWrap":false,"ads":[
<apex:repeat value="{!LstQuotes}" var="Listrec">
{"adId":"<apex:outputText value="{!Listrec.QuoteNumber}" />
","billingNumber":"<apex:outputText value="{!Listrec.AX_Arrangement_ID__c}" />
","filename":"<apex:outputText value="{!Listrec.Ad_Name__c}" />
","type":"<apex:outputText value="{!Listrec.Type__c}" />
","size":"<apex:outputText value="{!Listrec.Size__c}" />
","version":"<apex:outputText value="{!Listrec.Version__c}" />
","section":"<apex:outputText value="{!Listrec.Ad_Name__c}" />
","bleedCode":"<apex:outputText value="{!Listrec.Bleed_Code__c}" />
","properties":[
<apex:variable value="{!0}" var="rowNum"/>
<apex:repeat value="{!Listrec.QuoteLineItems}" var="Listrec2" rendered="{!Listrec.QuoteLineItems.size > 0}" >
<apex:variable var="rowNum" value="{!rowNum + 1}"/>
<apex:variable var="totRec" value="{!Listrec.Count_QuoteLineItemRec__c}"/>

{"propertyid":"<apex:outputText value="{!Listrec2.Account_SF_ID__c}"/>
","name":"<apex:outputText value="{!IF(rowNum == totRec, Listrec2.Advertiser_Account__r.Name + '}',  Listrec2.Advertiser_Account__r.Name + '},')}"/>
</apex:repeat>
]},
</apex:repeat>
</apex:page>

Thanks.
Martijn SchwarzerMartijn Schwarzer
Hi Ricardo,

Unfortunately, you cannot connect to an FTP server using Apex, you're right about that.
There is also no way to save files to a file system using apex (yet).

I'm trying to understand the context in which you want to save the records to a certain folder. 
Is this code part of a package? Maybe listed in the AppExchange?

If not, and you're only using the code internally in your org, you do have an alternative:

You can create a webservice to which you post the file. The web service should then save the file to the folder on the file system where you need it.
All you then need to do is to change the code for the button clicked by the user to call the web service and post the file.

Hope this helps!

Regards,
Martijn Schwärzer
RICARDO PALMARICARDO PALMA
Hi Martijn, thanks for your help. Yes, I'm using the code internally. I created the VF page to able to save the .json file. Do you have an example code: creating a webservice and connection to a FTP server. Thanks. *Ricardo Alberto Palma|* *Salesforce Developer* *|* *Dominion Enterprises* *6500 International Parkway, Ste 1000* *|* *Plano, TX 75093* *214-273-2103* (o) *|* *210-787-9353* (c) *|* *ricardo.palma@dominionenterprises.com *